1 solutions
-
-1
#include<bits/stdc++.h> using namespace std; long long t,n,m; int price[101][101]; //price[i][j]表示第i个物品在第j天的价格 int dp[100000]; //dp[i]表示当前用i元最多能赚到的钱(减去成本) int main() { cin >> t >> n >> m; for (int i=1;i<=t;i++){ for (int j=1;j<=n;j++){ cin >> price[j][i]; } } for (int d=1;d<t;d++){ //遍历天数 memset(dp,0,sizeof dp); //每天的决策是独立的,所以要清空dp数组 for (int i=1;i<=n;i++){ //物遍历品 for (int j=price[i][d];j<=m;j++){ //背包的,模板dp dp[j]=max(dp[j],dp[j-price[i][d]]+price[i][d+1]-price[i][d]); //转移方程:dp[i]=dp[当前拥有钱数-当前遍历到物品当天的价格]+该物品所能获得的利润 } } m+=dp[m]; //最终的利润是每天利润的总和 } cout << m; //输出 return 0; }
- 1
Information
- ID
- 4660
- Time
- 1000ms
- Memory
- 250MiB
- Difficulty
- 4
- Tags
- # Submissions
- 21
- Accepted
- 11
- Uploaded By