标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25602 Accepted Submission(s): 10836
// // main.cpp // hdu2191 // // Created by Candy on 9/21/16. // Copyright © 2016 Candy. All rights reserved. // #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=105; int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } int T,n,m,v,w,c; int f[N]; inline void cp(int v,int w){ for(int i=v;i<=n;i++) f[i]=max(f[i],f[i-v]+w); } inline void zp(int v,int w){ for(int i=n;i>=v;i--) f[i]=max(f[i],f[i-v]+w); } inline void mp(int v,int w,int c){ if(c*v>=n){cp(v,w);return;} int k=1; while(k<c){ zp(k*v,k*w); c-=k; k*=2; } zp(c*v,c*w); } int main(int argc, const char * argv[]) { T=read(); while(T--){ memset(f,0,sizeof(f)); n=read();m=read(); for(int i=1;i<=m;i++){ v=read();w=read();c=read(); mp(v,w,c); } int ans=0; for(int i=1;i<=n;i++) ans=max(ans,f[i]); printf("%d\n",ans); } return 0; }
HDU2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活[多重背包]
标签:
原文地址:http://www.cnblogs.com/candy99/p/5894676.html