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

32 lines
1.0 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种物品
if (w[t + 1][i] > w[t][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]);
//收益累加
m += f[m];
}
printf("%d\n", m);
return 0;
}