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.

30 lines
1.1 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种物品
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;
}