USACO-Score Inflation
来源:http://www.nocow.cn/index.php?diff=next&oldid=2732&title=Inflate_translate
这是一题非常标准的完全背包问题,不会的参见DD神牛的背包九讲
/* ID:ay27272 PROG:inflate LANG:C++ */ #include <cstdio> using namespace std; #define NN 10005 int d[NN]={0},w[NN]={0},f[NN]={0}; int main() { freopen("inflate.in","r",stdin); freopen("inflate.out","w",stdout); int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) scanf("%d%d",&d[i],&w[i]); for (int i=1;i<=m;i++) for (int j=w[i];j<=n;j++) if (f[j-w[i]]+d[i]>f[j]) f[j]=f[j-w[i]]+d[i]; printf("%d\n",f[n]); return 0; }