您的位置:首页 > 其它

POJ 1083 线性DP

2017-04-17 22:23 344 查看
题意:在一条走廊的两侧各有200个房间,现在给定一些成对的房间相互交换桌子,但是走廊每次只能通过一组搬运,  也就是说如果两个搬运过程有交叉是不能同时搬运的,要依次来,一次搬运10min,问完成所有的搬运的最少用时。 
思路:考虑每个房间有多少搬运过程需要经过,我们截取最大的房间经过的次数就可以了,挺锻炼思维的一道题。

代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 405;
int T, N, ans;

int room[maxn];
int main()
{
cin >> T;
while (T--) {
cin >> N;
ans = 0;
memset(room, 0, sizeof(room));
for (int i = 1; i <= N; ++i) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
if(x%2==0) x--;
if(y%2==1) y++;
for(int j = x; j <= y; ++j) {
room[j]++;
ans = max(ans, room[j]);
}
}
cout << ans * 10 << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: