Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我会再来的!#include<stdio.h> #include<stdlib.h> #include<memory.h> struct COW { int h; int a; int c; }; COW cow[405]; int dp[40005]; int max(int x,int y) { return (x)>(y)?(x):(y); } int cmp(const void * p1,const void * p2) { return ((COW *)p1)->a-((COW *)p2)->a; } int main() { // freopen("in.txt","r",stdin); int i,j,k,N; scanf("%d",&N); for(i=0;i<N;i++) { scanf("%d%d%d",&cow[i].h,&cow[i].a,&cow[i].c); } qsort(cow,N,sizeof(cow[0]),cmp); memset(dp,0,sizeof(dp)); //for(i=0;i<=cow[N-1].a;i++) // printf("%d->%d\n",i+1,dp[i]); for(i=0;i<N;i++) { for(j=0;j<cow[i].c;j++) { for(k=cow[i].a;k>=cow[i].h;k--) dp[k]=max(dp[k],dp[k-cow[i].h]+cow[i].h); } } // for(i=0;i<=cow[N-1].a;i++) // printf("%d->%d\n",i+1,dp[i]); printf("%d\n",dp[cow[N-1].a]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator