HDU 3401 Trade
Trade
This problem will be judged on HDU. Original ID: 3401
64-bit integer IO format: %I64d Java class name: Main
He forecasts the next T days' stock market. On the i'th day, you can buy one stock with the price APi or sell one stock to get BPi.
There are some other limits, one can buy at most ASi stocks on the i'th day and at most sell BSi stocks.
Two trading days should have a interval of more than W days. That is to say, suppose you traded (any buy or sell stocks is regarded as a trade)on the i'th day, the next trading day must be on the (i+W+1)th day or later.
What's more, one can own no more than MaxP stocks at any time.
Before the first day, lxhgww already has infinitely money but no stocks, of course he wants to earn as much money as possible from the stock market. So the question comes, how much at most can he earn?
Input
The first line of each case are three integers T , MaxP , W .
(0 <= W < T <= 2000, 1 <= MaxP <= 2000) .
The next T lines each has four integers APi,BPi,ASi,BSi( 1<=BPi<=APi<=1000,1<=ASi,BSi<=MaxP), which are mentioned above.
Output
Sample Input
1
5 2 0
2 1 1 1
2 1 1 1
3 2 1 1
4 3 1 1
5 4 1 1
Sample Output
3
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF = 0x3f3f3f3f;
int dp[maxn][maxn],q[maxn],p[maxn],hd,tl; int main(){
int kase,ap,bp,as,bs,n,m,w;
scanf("%d",&kase);
while(kase--){
scanf("%d%d%d",&n,&m,&w);
for(int i = ; i <= w + ; ++i){
scanf("%d%d%d%d",&ap,&bp,&as,&bs);
for(int j = ; j <= m; ++j){
dp[i][j] = j <= as?-ap*j:-INF;
if(i > ) dp[i][j] = max(dp[i][j],dp[i-][j]);
}
}
for(int i = w + ; i <= n; ++i){
scanf("%d%d%d%d",&ap,&bp,&as,&bs);
int k = i - w - ;
hd = tl = ;
for(int j = ; j <= m; ++j){
int tmp = dp[k][j] - ap*(m - j);
while(hd < tl && p[tl-] < tmp) --tl;
q[tl] = j;
p[tl++] = tmp;
while(hd < tl && j - q[hd] > as) ++hd;
dp[i][j] = max(dp[i-][j],p[hd] + ap*(m - j));
}
hd = tl = ;
for(int j = m; j >= ; --j){
int tmp = dp[k][j] + bp*j;
while(hd < tl && p[tl-] < tmp) --tl;
q[tl] = j;
p[tl++] = tmp;
while(q[hd] - j > bs) ++hd;
dp[i][j] = max(dp[i][j],p[hd] - bp*j);
}
}
printf("%d\n",dp[n][]);
}
return ;
}
HDU 3401 Trade的更多相关文章
- HDU 3401 Trade dp+单调队列优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...
- 【HDU 3401 Trade】 单调队列优化dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...
- HDU 3401 Trade(单调队列优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:炒股.第i天买入一股的价钱api,卖出一股的价钱bpi,最多买入asi股,最多卖出bsi股 ...
- HDU 3401 Trade(斜率优化dp)
http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:有一个股市,现在有T天让你炒股,在第i天,买进股票的价格为APi,卖出股票的价格为BPi,同时最多买 ...
- 【单调队列优化dp】HDU 3401 Trade
http://acm.hdu.edu.cn/showproblem.php?pid=3401 [题意] 知道之后n天的股票买卖价格(api,bpi),以及每天股票买卖数量上限(asi,bsi),问他最 ...
- hdu 3401 单调队列优化DP
Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu 3401 单调队列优化+dp
http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others) Memor ...
- HDU——1009FatMouse' Trade(贪心+结构体+排序)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 3401 单调队列优化动态规划
思路: 动态方程很容易想到dp[i][j]=max(dp[i][j],dp[i-w-1][j-k]-k*ap[i],dp[i-w-1][j+k]+k*bp[i]): dp[i][j]表示第i天拥有j个 ...
随机推荐
- Python猜年龄
题目:Python实现猜年龄 步骤一:实现最简单的猜年龄 # 事先定义 dark_knight_age = 28 user_age = input('Please guess my age:') us ...
- JS/CSS 压缩的好处
1.减小了文件的体积 2.减小了网络传输量和带宽占用 3.减小了服务器的处理的压力 4.提高了页面的渲染显示的速度
- 【BZOJ2595_洛谷4294】[WC2008]游览计划(斯坦纳树_状压DP)
上个月写的题qwq--突然想写篇博客 题目: 洛谷4294 分析: 斯坦纳树模板题. 简单来说,斯坦纳树问题就是给定一张有边权(或点权)的无向图,要求选若干条边使图中一些选定的点连通(可以经过其他点) ...
- Android开发之Intent.Action Android中Intent的各种常见作用
1 Intent.ACTION_MAIN String: android.intent.action.MAIN 标识Activity为一个程序的开始.比较常用. Input:nothing Outpu ...
- [转]Linux下paste命令详解
转自:http://blog.csdn.net/andy572633/article/details/7214126 paste单词意思是粘贴.该命令主要用来将多个文件的内容合并,与cut命令完成的功 ...
- unity多语言本地化
简介 嗯...一般来说做游戏啥的都不会只发一个国家,但是每个国家语言不同,就存在多语言本地化的问题,然后直接用过一个通过xml完成本地化的东东,然后策划反馈不会修改xml,扔给我一个excel让我自己 ...
- Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empid' in 'class cn.happy.entity.Emp'
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.i ...
- Laravel5.1学习笔记11 系统架构3 服务提供者
服务提供者 简介 写一个服务提供者 Register注册方法 Boot 方法 注册提供者 缓载提供者 简介 Service providers are the central place of all ...
- CSS知识点整理(2):框模型,定位
1. 框模型:Box Model 规定了元素处理元素框处理元素内容.外边距.边框.内边距的方式. 2. 当边距给定的值 可以小于4个.CSS定义了一些规则.处理这中情况: 如果缺少左外边距的值,则使用 ...
- Python3之format
print('{0},{1}'.format('zhangk', 32)) print('{},{},{}'.format('zhangk','boy',32)) print('{name},{sex ...