What am I doing, even the universal group will not test this problem. Mix the number of bzoj topics with the speed of a three or four-minute question.
BZOJ1606: [Usaco2008 dec]hay for Sale buy hay
The bare 01 backpack.
1#include <bits/stdc++.h>2 using namespacestd;3 Const intmaxn= the+5;4 Const intMaxc=50000+ -;5 6 intMain ()7 {8intC,H,V[MAXN],F[MAXC];9scanf"%d%d",&c,&h);TenMemset (F,0,sizeof(f)); One for(intI=1; i<=h;i++) A { -scanf"%d",&v[i]); - for(intj=c;j>=v[i];j--) F[j]=max (f[j],f[j-v[i]]+v[i]); the } -printf"%d", F[c]); -return 0; -}
BZOJ1625: [Usaco2007 Dec] Gemstone Bracelet
Bare 01 Backpack again ... Notice the little notes inside ...
1#include <bits/stdc++.h>2 using namespacestd;3 Const intmaxn=12880+5;4 5 intMain ()6 {7intdp[maxn],n,m;8Memset (DP,0,sizeof(DP));//If the need happens to fill up, then Dp[0]=0,dp[else]=-inf9scanf"%d%d",&n,&m);Ten for(intI=1; i<=n;i++) One { Aintw,d; -scanf"%d%d",&w,&d); - for(intj=m;j>=w;j--) Dp[j]=max (dp[j],dp[j-w]+d); the } -printf"%d", Dp[m]); -return 0; -}
BZOJ1677: [Usaco2005 jan]sumsets summation
Bare complete backpack. Previously written in a recursive version.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 Const intmaxn=1000000+ -;8 Const intMod=1e9;9 Ten intMain () One { AintN; -scanf"%d",&n); -intk=1, DP[MAXN]; theMemset (DP,0,sizeof(DP)); -dp[0]=1; - while(k<=N) - { + for(intv=k;v<=n;v++) dp[v]= (Dp[v]+dp[v-k])%MOD; -k=k*2; + } Aprintf"%d", dp[n]%MOD); atreturn 0; -}
BZOJ1655: [Usaco2006 Jan] Dollar Dayz Dairy Shop
Bare complete backpack, with high precision added.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn= ++ -;7 intF[MAXN][MAXN];8 9 voidAddintAintb)Ten { Oneintlena=f[a][0],lenb=f[b][0]; Aintlen=Max (LENA,LENB); -inti,rem=0; - for(i=1; I<=len | | rem;i++) the { -Rem= (F[a][i]+f[b][i])/Ten; -f[a][i]+=F[b][i]; -f[a][i]%=Ten; +f[a][i+1]+=rem; - } +f[a][0]=i-1; A } at - intMain () - { -intn,k; -scanf"%d%d",&n,&k); -Memset (F,0,sizeof(f)); inf[0][0]=f[0][1]=1; - for(intI=1; i<=k;i++) to for(intj=i;j<=n;j++) Add (j,j-i); + for(inti=f[n][0];i>=1; i--) printf ("%d", F[n][i]);p rintf ("\ n"); -return 0; the } *
"A pile of knapsack water problem" Addicted to brush water is hopeless ~