http://hihocoder.com/problemset/problem/1043
动态转移方程 :for v=cost..V
f[v]=max(f[v],f[v-c[i]]+w[i]);
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n,m; int dp[210000]={0}; void CompletePack(int cost,int weight) { for(int i=cost;i<=m;i++) { dp[i]=max(dp[i],dp[i-cost]+weight); } } int main() { int a,b; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%d%d",&a,&b); CompletePack(a,b); } printf("%d\n",dp[m]); return 0; }