#include <bits/stdc++.h>
using namespace std;
int M,N,w[205],c[205],f[205][205];
int main(){
cin>>M>>N;
for(int i=1;i<=N;i++) cin>>w[i]>>c[i];
for(int i=1;i<=N;i++){
for(int v=1;v<=M;v++){
if(v>=w[i]){
f[i][v]=max(f[i-1][v],f[i-1][v-w[i]]+c[i]);
}else{
f[i][v]=f[i-1][v];
}
}
}
cout<<f[N][M];
return 0;
}
01背包问题
最新推荐文章于 2024-08-18 17:01:18 发布