Time
Limit: 5000/2000 MS (Java/Others) Memory Limit:
65535/32768 K (Java/Others)
Total Submission(s):
2146 Accepted Submission(s):
953
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 int dp[101][101][10]; 6 struct goods 7 { 8 int a; //gooda price 9 int b; // 积分 10 int val ; // real price 11 }; 12 13 goods sta[105]; 14 int main() 15 { 16 int n,k,v1,v2,i,j,g,w,temans; 17 //freopen("test.in","r",stdin); 18 // freopen("test.out","w",stdout); 19 while(scanf("%d%d%d%d",&n,&v1,&v2,&k)!=EOF) 20 { 21 for(i=0;i<n;i++) 22 scanf("%d%d%d",&sta[i].a,&sta[i].b,&sta[i].val); 23 memset(dp,0,sizeof(dp)); 24 for(i=0;i<n;i++) 25 { 26 for(g=v1 ; g>=0 ;g--) 27 { 28 for(w=v2 ; w>=0 ; w--) 29 { 30 for(j=k ; j>=0 ; j--) 31 { 32 temans=0; 33 if( g>=sta[i].a && temans < dp[g-sta[i].a][w][j] + sta[i].val ) 34 temans = dp[g-sta[i].a][w][j] + sta[i].val ; 35 if( w>=sta[i].b && temans< dp[g][w-sta[i].b][j] + sta[i].val ) 36 temans = dp[g][w-sta[i].b][j] + sta[i].val ; 37 if( j>=1 && temans < dp[g][w][j-1] + sta[i].val ) 38 temans = dp[g][w][j-1] + sta[i].val ; 39 if(temans>dp[g][w][j])dp[g][w][j]=temans; 40 } 41 } 42 } 43 } 44 printf("%d\n",dp[v1][v2][k]); 45 } 46 return 0; 47 }
HDUOJ----4501小明系列故事——买年货(三维背包),布布扣,bubuko.com
HDUOJ----4501小明系列故事——买年货(三维背包)
原文:http://www.cnblogs.com/gongxijun/p/3600999.html