标签:
4 5 2 3 1 2 3 4 2 2
7
#include<stdio.h> #include<algorithm> using namespace std; int dp[10001],wi[101],vi[101]; const int INF=0x6fffffff;//0X3F3F3F3F;//; int main(){ int n,w; while(~scanf("%d%d",&n,&w)){ int sum=0,i,v; for(i=1;i<=n;++i){ scanf("%d%d",&wi[i],&vi[i]); sum+=vi[i]; } for(i=1;i<=sum;++i) dp[i]=INF; dp[0]=0; for(i=1;i<=n;++i){ for(v=sum;v>=vi[i];--v){ dp[v]=min(dp[v-vi[i]]+wi[i],dp[v]); } } for(i=sum;i>=0;--i){ if(dp[i]<=w) break; } printf("%d\n",i); } return 0; }
标签:
原文地址:http://www.cnblogs.com/hpuwyf/p/4401066.html