You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
512 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int M = 1010;
int n, m;
int w[N], v[N];
int f[N][M];
int main() {
cin >> m >> n;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
for (int i = 1; i <= n; i++)
for (int j = 1; 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]); // 选
}
printf("%d\n", f[n][m]);
return 0;
}