HDU 水题 背包问题 分组背包问题 注意 这个
1 for (int j=1;j<=M;j++) 2 scanf("%d",&A[j]);
不能写成这个
for (int j=0;j<M;j++) scanf("%d",&A[j]);
题目及AC代码 如下
Time Limit: 1000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 3626 Accepted
Submission(s): 1880
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 const int max_n=110; 6 7 int max(int a,int b) 8 { 9 return a>b?a:b; 10 } 11 12 int main(void) 13 { 14 int A[max_n]; 15 int dp[max_n]; 16 int M,N; 17 while(scanf("%d%d",&N,&M)&& (N!=0 && M!=0)) 18 { 19 memset(dp,0,sizeof(dp)); 20 memset(A,0,sizeof(A)); 21 for(int i=0;i<N;i++) 22 { 23 for (int j=1;j<=M;j++) 24 scanf("%d",&A[j]); 25 26 for(int vi=M;vi>=0;vi--) 27 { 28 for(int k=0;k<=vi;k++) 29 dp[vi]=max(dp[vi],dp[vi-k]+A[k]); 30 } 31 } 32 printf("%d\n",dp[M]); 33 } 34 35 36 return 0; 37 }
HDOJ 1712 ACboy needs your help,布布扣,bubuko.com
HDOJ 1712 ACboy needs your help
原文:http://www.cnblogs.com/VOID-133/p/3639127.html