poj3616 Milking Time

//题意:M个小时时间间隔内获取牛奶 再接下来有N个时间,但是每个时间段之间必须有R个休息时间
//每个时间段有个开始时间结束时间和生成牛奶数量,求出最大生成牛奶的可能数量
//思路:dp[i]表示用i为末尾时间的,生产的最大的牛奶数目类似最长子序列问题

//196K 16MS


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct mike_product{
	int start_time;
	int end_time;
	int nproduce;
};
int cmp(const mike_product&lhs,const mike_product&rhs){
	return lhs.start_time<rhs.start_time;
}
int main(){

	int N,M,R;
	scanf("%d %d %d",&N,&M,&R);
	vector<mike_product>vproduct;
	vproduct.resize(M+1);
	for(int i=1;i<=M;++i)
		scanf("%d %d %d",&vproduct[i].start_time,
             &vproduct[i].end_time,&vproduct[i].nproduce);
	sort(vproduct.begin(),vproduct.end(),cmp);
	
	vector<int>dp;
	dp.resize(M+1);
	for (int i=1;i<=M;++i)
	{
		dp[i] = vproduct[i].nproduce;
	}
	int ans = 0;
	for (int i=1;i<=M;++i)
	{
		for (int j=i;j>=1;--j)
		{
			if (vproduct[i].start_time>=(vproduct[j].end_time+R))
			{
				dp[i] = max(dp[i],dp[j]+vproduct[i].nproduce);
			}
	       ans = max(dp[i],ans);
		}
	}
	printf("%d\n",ans);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值