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个 ...
随机推荐
- 一款使用C# .NET开发的SIP网络电话客户端完整源码
一款使用C# .NET开发的SIP客户端开源项目.测试可编译通过运行,特此分享一下.可以对接ASTGO.VOS2009.VOS3000.NTS.UCS等各种SIP协议的软交换! 下载地址:https: ...
- [jzoj NOIP2018模拟10.23]
丢分主要是下面几个方面: 1.T2代码交错了,有个特判没写丢了10分 2.T1线段树加等差数列写错了(其实二维差分就可以,但我当时不会) 3.T3思考再三还是为了10分写上了主席树,还是写错了 总体评 ...
- ubuntu 更显列表 [Connecting to archive.ubuntu.com (2001:67c:1360:8001::21)] 超时的解决方法
问题描述: 在使用apt-get update 时更行列表,显示[Connecting to archive.ubuntu.com (2001:67c:1360:8001::21)]超时 分析: 我已 ...
- Salvation -- ---广搜 + 限定方向 ,
这个欣求 , 在迷宫里密室了方向 , 走过了一个地方 不做标记 还一个劲 , 找不到媳妇不亏 . 这个题 我跳了两个坑 , 1 : 习惯性添加标记走过的 位置 ,导致所有的位置都能 走过一遍 , ...
- Django总结三
回顾: - 装饰器 模板 - def wrapper(func): def inner(*args, **args): 执行被执行函数之前的操作 res = func(*args, **args) 执 ...
- 【BZOJ3110】[ZJOI2013]K大数查询(整体二分)
题目: BZOJ3110 分析: 整体二分模板题-- 先明确一下题意:每个位置可以存放多个数,第一种操作是"加入 (insert) "一个数而不是"加上 (add) &q ...
- 【Leetcode】92. Reverse Linked List II && 206. Reverse Linked List
The task is reversing a list in range m to n(92) or a whole list(206). All in one : U need three poi ...
- [转]mysql触发器的作用及语法
转自:http://blog.csdn.net/cloudday/article/details/6905590 触发器是一种特殊的存储过程,它在插入,删除或修改特定表中的数据时触发执行,它比数据库本 ...
- [转]Linux之ACL权限
转自:http://www.2cto.com/os/201110/108736.html 引言 前面的内容中,我们讲到传统的权限仅有三种身份(owner,group,others)搭配三种权限(r,w ...
- C#模拟百度登录并到指定网站评论回帖(一)
核心信息: 请求网址: https://passport.baidu.com/v2/api/?login请求方法: POST状态码: HTTP/1.1 200 OK请求头 //用户代理 Use ...