POJ 3616 Milking Time(DP)

来源:互联网 发布:火狐浏览器优化版 编辑:程序博客网 时间:2024/05/27 19:25

dp[i]= i-1时间段产奶量 + 现在的产奶量

#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<sstream>using namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;struct  node{int st, et, w;bool operator <(const node &b)const{return st < b.st;}}a[1000050];int dp[1000050];int main(){int n, m, r;cin >> n >> m >> r;for (int i = 0; i < m; ++i){scanf("%d%d%d", &a[i].st, &a[i].et, &a[i].w);a[i].et += r;}sort(a, a + m);memset(dp, 0, sizeof(dp));for (int i = 0; i < m; ++i){dp[i] = a[i].w;for (int j = 0; j < i; ++j){if (a[j].et <= a[i].st){dp[i] = max(dp[i], dp[j] + a[i].w);}}}//cout << dp[n-1] << endl;//找出数组里面最大的数 返回指针cout << *max_element(dp, dp + m) << endl;return 0;}


0 0
原创粉丝点击