完全背包足以,参照完全背包最优解就过了
/*ID: hubiao cavePROG: inflateLANG: C++*/#include<iostream>#include<fstream> #include<cstring> #include<string>using namespace std;int main(){ifstream fin("inflate.in");ofstream fout("inflate.out");int f[10003];int w[10003];int v[10003];int num,minute;fin>>minute>>num;for(int i=1;i<=num;i++ ){fin>>v[i]>>w[i];}memset(f,0,10003*4);for(int i=1;i<=num;i++)for(int j=0;j<=minute;j++){if(j>=w[i])f[j]=max(f[j],f[j-w[i]]+v[i]);}fout<<f[minute]<<endl;return 0;}