标签:des style blog color java io strong for 数据
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3046 Accepted Submission(s):
1197
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { int s,e,c; } num[1005]; int dp[105]; int cmp(node a,node b)//结束时间 { if(a.e==b.e) return a.c>b.c; return a.e<b.e; } int main() { int T,i,j,k; int m,n; scanf("%d",&T); while(T--) { scanf("%d%d",&m,&n); memset(dp,0,sizeof(dp)); for(i=0; i<n; i++) scanf("%d%d%d",&num[i].s,&num[i].e,&num[i].c); sort(num,num+n,cmp); for(i=0; i<n; i++) { if(num[i].e>m) break; for(j=num[i].e; j<=m; j++) { dp[j]=max(dp[j],dp[num[i].s-1]+num[i].c); } } printf("%d\n",dp[m]); } return 0; }
//减1是因为闭区间[s,e]; cuo!
标签:des style blog color java io strong for 数据
原文地址:http://www.cnblogs.com/yuyixingkong/p/3944623.html