4437: 纪念品

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:5 解决:2

题目描述

小伟突然获得一种超能力,他知道未来 lns="http://www.w3.org/1998/Math/MathML"> 天 lns="http://www.w3.org/1998/Math/MathML"> 种纪念品每天的价格。某个纪念品的价格是指购买一个该纪念品所需的金币数量,以及卖出一个该纪念品换回的金币数量。

每天,小伟可以进行以下两种交易无限次

  1. 任选一个纪念品,若手上有足够金币,以当日价格购买该纪念品;
  2. 卖出持有的任意一个纪念品,以当日价格换回金币。

每天卖出纪念品换回的金币可以立即用于购买纪念品,当日购买的纪念品也可以当日卖出换回金币。当然,一直持有纪念品也是可以的。

lns="http://www.w3.org/1998/Math/MathML"> 天之后,小伟的超能力消失。因此他一定会在第 lns="http://www.w3.org/1998/Math/MathML"> 天卖出所有纪念品换回金币。

小伟现在有 lns="http://www.w3.org/1998/Math/MathML"> 枚金币,他想要在超能力消失后拥有尽可能多的金币。

输入

第一行包含三个正整数 lns="http://www.w3.org/1998/Math/MathML">,,,相邻两数之间以一个空格分开,分别代表未来天数 lns="http://www.w3.org/1998/Math/MathML">,纪念品数量 lns="http://www.w3.org/1998/Math/MathML">,小伟现在拥有的金币数量 lns="http://www.w3.org/1998/Math/MathML">

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行包含 lns="http://www.w3.org/1998/Math/MathML"> 个正整数,相邻两数之间以一个空格分隔。第 lns="http://www.w3.org/1998/Math/MathML"> 行的 lns="http://www.w3.org/1998/Math/MathML"> 个正整数分别为 lns="http://www.w3.org/1998/Math/MathML">,1,,2,,,,其中 lns="http://www.w3.org/1998/Math/MathML">, 表示第 lns="http://www.w3.org/1998/Math/MathML"> 天第 lns="http://www.w3.org/1998/Math/MathML"> 种纪念品的价格。

输出

输出仅一行,包含一个正整数,表示小伟在超能力消失后最多能拥有的金币数量。

样例输入 复制

6 1 100
50
20
25
20
25
50

样例输出 复制

305

提示


输入 #2
3 3 100
10 20 15
15 17 13
15 25 16
输出 #2
217



样例 1 说明

最佳策略是:

第二天花光所有 lns="http://www.w3.org/1998/Math/MathML">100 枚金币买入 lns="http://www.w3.org/1998/Math/MathML">5 个纪念品 lns="http://www.w3.org/1998/Math/MathML">1

第三天卖出 lns="http://www.w3.org/1998/Math/MathML">5 个纪念品 lns="http://www.w3.org/1998/Math/MathML">1,获得金币 lns="http://www.w3.org/1998/Math/MathML">125 枚;

第四天买入 lns="http://www.w3.org/1998/Math/MathML">6 个纪念品 lns="http://www.w3.org/1998/Math/MathML">1,剩余 lns="http://www.w3.org/1998/Math/MathML">5 枚金币;

第六天必须卖出所有纪念品换回 lns="http://www.w3.org/1998/Math/MathML">300 枚金币,第四天剩余 lns="http://www.w3.org/1998/Math/MathML">5 枚金币,共 lns="http://www.w3.org/1998/Math/MathML">305 枚金币。

超能力消失后,小伟最多拥有 lns="http://www.w3.org/1998/Math/MathML">305 枚金币。

样例 2 说明

最佳策略是:

第一天花光所有金币买入 lns="http://www.w3.org/1998/Math/MathML">10 个纪念品 lns="http://www.w3.org/1998/Math/MathML">1

第二天卖出全部纪念品 lns="http://www.w3.org/1998/Math/MathML">1 得到 lns="http://www.w3.org/1998/Math/MathML">150 枚金币并买入 lns="http://www.w3.org/1998/Math/MathML">8 个纪念品 lns="http://www.w3.org/1998/Math/MathML">2 和 lns="http://www.w3.org/1998/Math/MathML">1 个纪念品 lns="http://www.w3.org/1998/Math/MathML">3,剩余 lns="http://www.w3.org/1998/Math/MathML">1 枚金币;

第三天必须卖出所有纪念品换回 lns="http://www.w3.org/1998/Math/MathML">216 枚金币,第二天剩余 lns="http://www.w3.org/1998/Math/MathML">1 枚金币,共 lns="http://www.w3.org/1998/Math/MathML">217 枚金币。

超能力消失后,小伟最多拥有 lns="http://www.w3.org/1998/Math/MathML">217 枚金币。

数据规模与约定

对于 lns="http://www.w3.org/1998/Math/MathML">10% 的数据,lns="http://www.w3.org/1998/Math/MathML">=1

对于 lns="http://www.w3.org/1998/Math/MathML">30% 的数据,lns="http://www.w3.org/1998/Math/MathML">4,4,100,所有价格 lns="http://www.w3.org/1998/Math/MathML">10,100

另有 lns="http://www.w3.org/1998/Math/MathML">15% 的数据,lns="http://www.w3.org/1998/Math/MathML">100,=1

另有 lns="http://www.w3.org/1998/Math/MathML">15% 的数据,lns="http://www.w3.org/1998/Math/MathML">=2,100

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">100,100,103,所有价格 lns="http://www.w3.org/1998/Math/MathML">1,104,数据保证任意时刻,小明手上的金币数不可能超过 lns="http://www.w3.org/1998/Math/MathML">104

#include<bits/stdc++.h>
using namespace std;
int p[110][110];//存储所有的物品每天的价格 
int f[10010]; //最大收益
int t,n,m;
int main(){
    cin>>t>>n>>m; //读入t天每天的n个物品的价格
    for(int i=1;i<= t;i++){
        for(int j= 1;j<= n;j++){
            cin>>p[i][j];
        }
    }
    //进行t-1次交易(完全背包)
    for(int i=1;i< t;i++){
        memset(f,0,sizeof(f)); //循环n个物品
        for(int j= 1;j<= n;j++){ //如果涨价的情况下,产生交易
            if(p[i][j]< p[i+1][j]){ //循环物品重量(价格)~背包容量
                for(int k= p[i][j];k<= m;k++){
                    f[k]= max(f[k],f[k-p[i][j]]+(p[i+1][j]-p[i][j]));
                }
            }
        }
    m += f[m];
    }
    cout<<m;
    return 0;
}