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.

38 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 110; // 野生小精灵的数量
const int M1 = 1010; // 小智的精灵球数量
const int M2 = 510; // 皮卡丘的体力值
int n, m1, m2;
int f[M1][M2]; // 一维:精灵球数量,二维:皮卡丘的体力值,值:抓到的小精灵数量最大值
int main() {
cin >> m1 >> m2 >> n;
m2--; // 留一滴血
// 二维费用01背包
// 降维需要将体积1、体积2倒序枚举
for (int i = 1; i <= n; i++) {
int v1, v2;
cin >> v1 >> v2;
for (int j = m1; j >= v1; j--)
for (int k = m2; k >= v2; k--)
f[j][k] = max(f[j][k], f[j - v1][k - v2] + 1); // 获利就是多了一个小精灵
}
// 最多收服多少个小精灵[在消耗精灵球、血极限的情况下,肯定抓的是最多的,这不废话吗]
printf("%d ", f[m1][m2]);
// 找到满足最大价值的所有状态里,第二维费用消耗最少的
int cost = m2;
for (int i = 0; i <= m2; i++) // 如果一个都不收服则体力消耗最少消耗值为0
if (f[m1][i] == f[m1][m2])
cost = min(cost, i);
// 收服最多个小精灵时皮卡丘的剩余体力值最大是多少
printf("%d\n", m2 + 1 - cost);
return 0;
}