#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int f[N],t,m,w[N],v[N];
int main() {
ios::sync_with_stdio(false);
cin>>t>>m;
for(register int i=0;i<m;++i) {
cin>>w[i]>>v[i];
}
for(register int i=0;i<m;++i) {
//和0/1背包相比将顺序反过来 每件物品可以放n次
for(register int j=w[i];j<=t;++j) {
f[j]=max(f[j],f[j-w[i]]+v[i]);
}
}
cout<<f[t];
}
完全背包 (01背包反过来)
最新推荐文章于 2021-09-20 15:38:52 发布