标签:des style blog io color ar os java sp
3 3 3 7 7 9 9 10 5 1 1 5 3 10 3 6 8 7 5 6
10 20/*还是完全背包问题,注意数组开的大小要合适,否则可能会溢出*/ #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int n,a[102],b[102],dp[100002]; int i,j,m; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%d %d",&a[i],&b[i]); } memset(dp,0,sizeof(dp)); scanf("%d",&m); for(i=1;i<=n;i++) { for(j=b[i];j<=m;j++) dp[j]=max(dp[j],dp[j-b[i]]+a[i]); } printf("%d\n",dp[m]); } return 0; }
标签:des style blog io color ar os java sp
原文地址:http://blog.csdn.net/hdd871532887/article/details/40961029