Files
python/TangDou/CSP-J/J2_2019/3_YiWei_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 10010;
int T, n, m;
int f[M];
int w[N][N]; //第i天,第j支股票的价格
int main() {
//未来天数 T,纪念品数量 N,小伟现在拥有的金币数量 M
cin >> T >> n >> m;
for (int i = 1; i <= T; i++) //未来T天
for (int j = 1; j <= n; j++) //每个纪念品
cin >> w[i][j]; //价格
for (int t = 1; t < T; t++) { //枚举每一天
memset(f, 0, sizeof f); // dp数组
for (int i = 1; i <= n; i++) //枚举前i种物品
for (int j = w[t][i]; j <= m; j++) //枚举剩余体积
f[j] = max(f[j], f[j - w[t][i]] + w[t + 1][i] - w[t][i]); //收益=w[t + 1][i] - w[t][i]
//因为赚了钱,所以后面一天的初始金额变大,这是一个逐步累加的过程.也就是背包容量变大
m += f[m];
}
printf("%d\n", m);
return 0;
}