POJ 1083 线性DP

题意:在一条走廊的两侧各有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;
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TWSF

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值