poj3616(LIS)

点击打开链接

/*
translation:
	一头奶牛每天在一些特定的时间段产奶,每次产奶之后必须休息r分钟。现在给出每天的产奶间隔和
	每个间隔的产奶量,求该头奶牛的一天可以产奶最高多少?
	
solution:
	LIS, dp即可解。
	
note:
	1:一开始被给出的时间n所干扰,但是这其实是无用条件。
	2:善于从题目中抽象出经典模型。
	3:poj上的FJ和Bessie是真爱,tm哪儿都有他俩!!
	
date:
	2016.9.1
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1001;

struct Interval {
	int s, e, d;
	Interval(int s_, int e_, int d_) : s(s_), e(e_), d(d_) {}
	Interval() {}
	bool operator < (const Interval& rhs) const {
		if(s == rhs.s)	return e < rhs.e;
		else			return s < rhs.s;
	}
} intervals[maxn];
int n, m, r;
int dp[maxn];	//以第i个间隔为最后间隔所获得的最优解

int main()
{
	//freopen("in.txt", "r", stdin);
    while(~scanf("%d%d%d", &n, &m, &r)) {
		for(int i = 0; i < m; i++) {
			scanf("%d%d%d", &intervals[i].s, &intervals[i].e, &intervals[i].d);
		}

		sort(intervals, intervals + m);
		memset(dp, 0, sizeof(dp));

		int ans = -1;
		for(int i = 0; i < m; i++) {
			dp[i] = intervals[i].d;
			for(int j = 0; j < i; j++) {
				if(intervals[i].s - intervals[j].e >= r) {
					dp[i] = max(dp[i], dp[j] + intervals[i].d);
				}
			}
			ans = max(ans, dp[i]);
		}

		printf("%d\n", ans);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值