标签:
43
先把读入的区间从小到大排序,然后dp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10005;
struct node
{
int l,r,data;
bool operator<(const node& tmp) const{
if(l!=tmp.l)
return l<tmp.l;
else
return r<tmp.r;
}
}p[maxn];
int dp[maxn];//表示选择到第M个区间 能获得的最大值
int main()
{
int n,m,r;
while(~scanf("%d%d%d",&n,&m,&r)){
for(int i=0;i<m;i++){
scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].data);
dp[i]=0;
}
sort(p,p+m);
int j;
for(int i=0;i<m;i++){
int maxx=0;
for(j=0;j<i;j++)if(p[i].l-p[j].r>=r){
maxx=max(maxx,dp[j]);//找到这个区间前面的最大值
}
dp[i]=maxx+p[i].data;
}
printf("%d\n",*max_element(dp,dp+m+1));
}
return 0;
}
R - Milking Time POJ 3616 ( DP )
标签:
原文地址:http://blog.csdn.net/u013167299/article/details/45889349