Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 27002 Accepted
Submission(s): 10938
01背包模板题:
1 //15MS 240K 545 B C++ 2 #include<stdio.h> 3 #include<string.h> 4 int dp[1005]; 5 int v[1005],w[1005]; 6 int Max(int a,int b) 7 { 8 return a>b?a:b; 9 } 10 int main(void) 11 { 12 int t,n,m; 13 scanf("%d",&t); 14 while(t--) 15 { 16 scanf("%d%d",&n,&m); 17 memset(dp,0,sizeof(dp)); 18 for(int i=1;i<=n;i++) scanf("%d",&v[i]); 19 for(int i=1;i<=n;i++) scanf("%d",&w[i]); 20 for(int i=1;i<=n;i++) 21 for(int j=m;j>=w[i];j--) 22 dp[j]=Max(dp[j],dp[j-w[i]]+v[i]); 23 printf("%d\n",dp[m]); 24 } 25 return 0; 26 }
hdu 2602 Bone Collector (01背包),布布扣,bubuko.com
hdu 2602 Bone Collector (01背包)
原文:http://www.cnblogs.com/GO-NO-1/p/3740502.html