宠物小精灵之收服
https://www.acwing.com/problem/content/1024/
二维01背包
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define VIT vector<int>
#define x first
#define y second
#define inf 0x3f3f3f3f
int f[1010][510];
int main() {
//freopen("in.txt", "r", stdin);
IO;
int v1, v2, n;
cin >> v1 >> v2 >> n;
for (int i = 1; i <= n; ++i) {
int a, b;
cin >> a >> b;
for (int j = v1; j >= a; --j)
for (int k = v2 - 1; k >= b; --k)
f[j][k] = max(f[j][k], f[j - a][k - b] + 1);
}
int a = f[v1][v2 - 1], b;
for (int i = v2 - 1; i; --i)
if (f[v1][i] != a) {
b = v2 - i - 1;
break;
}
if (a == 0) b = v2;
cout << a << ' ' << b << '\n';
return 0;
}