1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std;
const int N = 30, M = 30010;
int n, m; int f[M];
int main() { cin >> m >> n; for (int i = 1; i <= n; i ++ ) { int v, w; cin >> v >> w; w = v * w; for (int j = m; j >= v; j -- ) f[j] = max(f[j], f[j - v] + w); } cout << f[m] << endl; return 0; }
|