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.2 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
int n, v, m; //n:物品件数、v:背包容积,m:背包可承受的最大重量
int f[101][101]; //dp[i][j]:表示总体积是i,重量为j的情况下最大价值是多少
int a, b, c; //表示第 i 件物品的体积、重量和价值。
// 二维背包
/*
10^7
->01
->
dp[i][j]:i,j
*/
int main() {
//输入+输出重定向
freopen("../1301.txt", "r", stdin);
cin >> n >> v >> m;
//从前往后枚举物品
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
//体积从大到小枚举
for (int j = v; j >= a; j--)
for (int k = m; k >= b; k--) //重量从大到小枚举
f[j][k] = max(f[j][k], f[j - a][k - b] + c); //状态转移方程
}
cout << f[v][m] << endl;
//关闭文件
fclose(stdin);
return 0;
}