#include <iostream>
using namespace std;
const int N = 110, M = 1010;
int n, m;
int w[N], v[N];
int f[N][M];
int main()
{
//input
cin >> m >> n;
for (int i = 1; i <= n; ++ i) cin >> v[i] >> w[i];
//dp
for (int i = 1; i <= n; ++ i)
{
for (int j = 0; j <= m; ++ j)
{
f[i][j] = f[i - 1][j];//不选
if (j >= v[i]) f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]);//选
}
}
//output
cout << f[n][m] << endl;
return 0;
}
423. 采药 01背包
最新推荐文章于 2024-11-09 21:51:15 发布