代码:
/* 二维费用背包问题 */ #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 110; int n, v, m; int dp[N][N]; int main() { cin >> n >> v >> m; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; for (int j = v; j >= a; j--) { for (int k = m; k >= b; k--) { dp[j][k] = max(dp[j][k], dp[j - a][k - b] + c); } } } cout << dp[v][m] << endl; return 0; }
原文地址:https://www.cnblogs.com/gcter/p/11344932.html
时间: 2024-10-06 11:01:03