首页 > 代码库 > poj3642 01背包

poj3642 01背包

http://poj.org/problem?id=3624

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int z[3405],v[3405];int dp[12885];int main(){    int N,M;    while(cin>>N>>M)    {        memset(dp,0,sizeof(dp));        for(int i=1; i<=N; i++)            cin>>z[i]>>v[i];        for(int i=1; i<=N; i++)            for(int j=M; j>=z[i]; j--)                dp[j]=max(dp[j],dp[j-z[i]]+v[i]);        cout<<dp[M]<<endl;    }    return 0;}

 

poj3642 01背包