problem
solution
codes
//dp[i+1][j]:从0到i+1这个物品中选出总重量不超过j的物品时总价值的最大值
#include<iostream>
#include<algorithm>
using namespace std;
int n, s, w[5050], k[5050], dp[5050][5050];
int main(){
cin>>s>>n;
for(int i = 0; i < n; i++)cin>>w[i]>>k[i];
for(int i = 0; i < n; i++){
for(int j = 0; j <= s; j++){
if(w[i] <= j)dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+k[i]);
else dp[i+1][j] = dp[i][j];
}
}
cout<<dp[n][s];
return 0;
}