标签:des style blog io color os sp java for
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3108 Accepted Submission(s): 1220
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn=105; 7 int dp[maxn]; 8 inline int max(int a,int b){return a>b?a:b;} 9 struct node 10 { 11 int s,e,val; 12 bool operator <=(const node a)const{ 13 if(e!=a.e) return e<=a.e; 14 else return s<=a.s; 15 } 16 bool operator >=(const node a)const{ 17 if(e!=a.e) return e>=a.e; 18 else return s>=a.s; 19 } 20 }p[1005]; 21 void swap(node &a,node &b){node t=a;a=b;b=t;} 22 void qsort(int l,int r) 23 { 24 if(l<r) 25 { 26 node t=p[l]; 27 int i=l,j=r; 28 while(i!=j) 29 { 30 while(p[j]>=t && i<j) j--; 31 while(p[i]<=t && i<j) i++; 32 if(i<j) swap(p[i],p[j]); 33 } 34 p[l]=p[i];p[i]=t; 35 qsort(l,i-1); 36 qsort(i+1,r); 37 } 38 } 39 40 int main() 41 { 42 int t,m,n,i,j; 43 scanf("%d",&t); 44 while(t--) 45 { 46 scanf("%d%d",&m,&n); 47 memset(dp,0,sizeof(dp)); 48 for(i=1;i<=n;i++) scanf("%d%d%d",&p[i].s,&p[i].e,&p[i].val); 49 qsort(1,n); 50 //for(i=1;i<=n;i++) printf("%d %d %d\n",p[i].s,p[i].e,p[i].val); 51 for(i=1;i<=m;i++) 52 for(j=1;j<=n;j++) 53 { 54 if(p[j].e>i) break; 55 dp[i]=max(dp[i],dp[p[j].s-1]+p[j].val); 56 } 57 printf("%d\n",dp[m]); 58 } 59 return 0; 60 }
标签:des style blog io color os sp java for
原文地址:http://www.cnblogs.com/xiong-/p/4100920.html