POJ 3616 Milking Time

题意

给m只奶牛挤奶,挤奶时间必须处于[1, n];
给出每次开始挤奶的时间st,结束挤奶的时间ed,还有挤奶的量ef;
每次挤完奶要休息r时间;
问: 最大挤奶量为?

题解

[线性DP--LIS模型]
分析:
    题意就等效于找一段满足条件的挤奶序列,使得挤奶量最多
    故而,只需要将原序列按照时间序递增的排序,
    在利用求LIS的思路即可

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define read(a) scanf("%d", &a)
#define readf(a) scanf("%lf", &a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
struct node
{
    int st, ed, val;
    bool operator<(const node& A)const{
        return st < A.st || (st == A.st && ed < A.ed);
    }
}a[N];
int dp[N];
signed main()
{
    Buff;
    int n, m, R;
    while(cin >> n >> m >> R)
    {
        for(int i = 1; i <= m; i++)
            cin >> a[i].st >> a[i].ed >> a[i].val;
        sort(a + 1, a + m + 1);
        int ans = 0;
        for(int i = 1; i <= m; i++)
        {
            if(a[i].st > n || a[i].ed > n) continue;
            dp[i] = a[i].val;
            for(int j = 1; j < i; j++)
                if(a[j].ed + R <= a[i].st && dp[j] + a[i].val > dp[i])  dp[i] = dp[j] + a[i].val;
            if(dp[i] > ans) ans = dp[i];
        }
        cout << ans << "\n";
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值