标签:style blog http io ar color os sp for
4 5 2 3 1 2 3 4 2 2
7
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define N 100010 int n,s; int w[N]; int v[N]; int dp[N]; int main() { int i,j; while(scanf("%d%d",&n,&s)!=EOF) { int sum=0; for(i=1;i<=n;i++) { scanf("%d%d",&w[i],&v[i]); sum+=v[i]; } memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(i=1;i<=n;i++) { for(j=sum;j>=v[i];j--) { dp[j]=min(dp[j],dp[j-v[i]]+w[i]); } } for(j=sum;j>=0;j--) { if(dp[j]<=s) { cout<<j<<endl; break; } } } return 0; }
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/hate13/p/4138970.html