P1757-a group backpack
hdu1712 Acboy needs your help
hdu1712 test instructions: a[i][j] means that J-day learning of the first Class I can get the benefit of a[i][j], the maximum value obtained within M days, only one lesson per day (turn).
Group Backpack Routines:
for (int i=1; i<= group number; + +i ) for (int j= capacity; j>=0;---j) for (int k=1; number of elements in Group I of k<=; + +k) ...
Ensure a group of only <=1
hdu1712 Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineRe Register5 using namespacestd;6 intMaxint&a,int&B) {returnA>b?a:b;}7 intn,m,a[102][102],f[102];8 intMain () {9 while(~SCANF ("%d%d",&n,&m)) {Ten if(!n&&!m) Break; One for(ReintI=1; i<=n;++i) A for(Reintj=1; j<=m;++j) -scanf"%d",&a[i][j]); -Memset (F,0,sizeof(f)); the for(ReintI=1; i<=n;++i) - for(Reintj=m;j>=0;--j) - for(Reintk=1; k<=j;++k) -F[j]=max (f[j],f[j-k]+a[i][k]); +printf"%d\n", F[m]); -}return 0; +}
View Code
P1757 Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineRe Register5 using namespacestd;6 intMaxint&a,int&B) {returnA>b?a:b;}7 intn,m,f[1002];8 intlen[ +],a[1002][1002],b[1002][1002];9 intMain () {Ten intQ1,Q2,Q3,MC; One while(~SCANF ("%d%d",&m,&N)) { Amemset (Len,0,sizeof(len)); -Memset (F,0,sizeof(f)); -Mc=0; the for(ReintI=1; i<=n;++i) { -scanf"%d%d%d",&q1,&q2,&Q3); -Mc=Max (MC,Q3); -a[q3][++len[q3]]=Q1; +b[q3][len[q3]]=Q2; - } + for(ReintI=1; i<=mc;++i) A for(Reintj=m;j>=0;--j) at for(Reintu=1; u<=len[i];++u) - if(j>=A[i][u]) -F[j]=max (f[j],f[j-a[i][u]]+B[i][u]); -printf"%d\n", F[m]); -}return 0; -}
View Code
P1757 Babel Pack/hdu1712 Acboy needs your help (Group Backpack Primer)