BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草
背包
#include<cstdio> using namespace std; int F[1000005]; int main(){ int V,q; scanf("%d%d",&V,&q); F[0]=1; while (q--){ int x; scanf("%d",&x); for (int i=V; i>=x; i--) F[i]|=F[i-x]; } for (int i=V; i>=0; i--) if (F[i]){ printf("%d\n",i); return 0; } return 0; }