This is a typical dp,f[i][j],i of the horizontal axis, J for the ordinate, each horizontal axis with a complete backpack to calculate, some of the special, please understand in the program:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#defineMAXN 10010using namespacestd;Const intinf=0x7ffffff;intn,m,k,p,l,h;intX[MAXN],Y[MAXN],DOWN[MAXN],UP[MAXN];intf[maxn][1001];intMain () {Freopen ("bird.in","R", stdin); Freopen ("Bird.out","W", stdout); scanf ("%d%d%d",&n,&m,&k); for(intI=0; i<n;i++) scanf ("%d%d",&x[i],&Y[i]); for(intI=1; i<=n;i++) {Down[i]=0; Up[i]=m+1; } for(intI=1; i<=k;i++) {cin>>p>>l>>h; DOWN[P]=M; UP[P]=h; } for(intI=1; i<=n;i++) for(intj=0; j<=m;j++) F[i][j]=inf; f[0][0]=inf; intArrive=K; for(intI=1; i<=n;i++) { for(intj =1; J <= M; J + +) { if(J >= x[i-1]) {F[i][j]= Min (F[i][j], f[i-1][j-x[i-1]] +1); F[I][J]= Min (F[i][j], f[i][j-x[i-1]] +1); } if(J = =m) { for(intk=j-x[i-1];k<=m;k++) {F[i][j]= Min (F[i][j], f[i-1][K] +1); F[I][J]= Min (F[i][j], f[i][k] +1); } } } for(intj = down[i]+1; J <= up[i]-1; ++j)if(j + y[i-1] <=m) F[i][j]= Min (F[i][j], f[i-1][j+y[i-1]]); for(intj =1; J <= Down[i]; J + +) F[i][j] =inf; for(intj = Up[i]; J <= M; J + +) F[i][j] =inf; } intcnt = k, ans =inf; for(inti = n; I >=1; i--) { for(intj = down[i]+1; J <= up[i]-1; ++j)if(F[i][j] <inf) ans=min (ans, f[i][j]); if(ans = inf) Break; if(Up[i] <=m) CNT--; } if(cnt==k) printf ("1\n%d\n", ans); Elseprintf ("0\n%d\n", CNT); return 0;}
Qing impartiality and is shot life pill is also ~
Day1 Flying Birds