解题思路:
注意事项:
参考代码:
#include<iostream>
using namespace std;
int w[31];
int c[31];
int dp[201] = {0};
int main()
{
int m, n;
cin >> m >> n;
for (int i = 0; i < n; i++) {
cin >> w[i] >> c[i];
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = m; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + c[i]);
}
}
cout << dp[m] << endl;
return 0;
}
0.0分
0 人评分