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.

32 lines
1.0 KiB

2 years ago
#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;
}