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;
#define maxV 1000
/**
* 2. 完全背包
1)题目:
有n件物品和一个容量为v的背包,每种物品都有无限件可用。
第i种物品的费用是c[i],价值是w[i]。
求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。
2)输入:
测试用例数
物品数 背包容量
n个物品的ci和vi
*/
int main(void) {
int cases, n, v, ci, wi;
int f[maxV];
freopen("../2.txt", "r", stdin);
cin >> cases;
while (cases--) {
memset(f, 0, sizeof(f));
cin >> n >> v;
for (int i = 0; i < n; i++) {
cin >> ci >> wi;
for (int j = 0; j <= v; j++) {
if (j >= ci)
f[j] = max(f[j], f[j - ci] + wi);
}
cout << f[v] << endl;