hdu 3401 单调队列优化dp
来源:互联网 发布:mac翻墙代理软件 编辑:程序博客网 时间:2024/05/24 05:03
Recently, lxhgww is addicted to stock, he finds some regular patterns after a few days’ study.
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?
一个股神,可以预测股市行情的天才.
#include<stdio.h>#include<algorithm>using namespace std;int t,ap,bp,as,bs,dp[2004][2004],q[2004],v[2004],l,r;int n,maxp,w;inline const int read(){ register int x=0,f=1; register char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return f*x;}int main(){ t=read(); while(t--) { n=read(),maxp=read(),w=read(); register int i,j; for(i=1;i<=w+1;i++) { ap=read(),bp=read(),as=read(),bs=read(); for(j=0;j<=maxp;j++) { if(j<=as) dp[i][j]=-j*ap; else dp[i][j]=-210000000; if(i>1) dp[i][j]=max(dp[i][j],dp[i-1][j]); } } for(register int i=w+2;i<=n;i++) { ap=read(),bp=read(),as=read(),bs=read(); int k=i-w-1; l=0,r=-1; for(j=0;j<=maxp;j++) { int tmp=dp[k][j]-ap*(maxp-j); while(l<=r&&tmp>v[r]) r--; q[++r]=j; v[r]=tmp; while(j-q[l]>as) l++; dp[i][j]=max(dp[i-1][j],v[l]+ap*(maxp-j)); } l=0,r=-1; for(j=maxp;j>=0;j--) { int tmp=dp[k][j]+bp*j; while(l<=r&&tmp>v[r]) r--; q[++r]=j; v[r]=tmp; while(q[l]-j>bs) l++; dp[i][j]=max(dp[i][j],v[l]-bp*j); } } printf("%d\n",dp[n][0]); }}
- hdu 3401 Trade(DP+单调队列优化)
- hdu 3401 Trade 单调队列优化dp
- hdu 3401 单调队列优化+dp
- hdu 3401 Trade 单调队列优化dp
- hdu 3401 Trade(单调队列优化dp)
- hdu 3401 单调队列优化DP
- hdu 3401 单调队列优化dp
- HDU 3401 Trade 单调队列优化DP
- HDU 3401 Trade 【DP+单调队列优化】
- Hdu 3401 题解 单调队列优化DP
- hdu 3401 单调队列优化dp
- hdu 3401(单调队列优化dp)
- HDU 3401 Trade (单调队列优化DP)
- hdu-3401-Trade-单调队列优化的DP
- HDU-3401:Trade(dp+单调队列优化)
- HDU 3401 Trade(单调队列优化DP)【模板】
- HDU 3401 Trade(用单调队列优化DP)
- HDU 3401 DP+单调队列
- 两种创建线程的方式/线程的生命周期及各自使用同步锁时的区别
- 如何用Python写一个安卓APP
- Universal-Image-Loader源码收获
- Unsupported major.minor version 52.0异常
- .NET Reflector Visual Studio Extension
- hdu 3401 单调队列优化dp
- target-action
- android中RecyclerView的简单使用(二)——分割线
- Yii学习笔记1-介绍和详细运行过程
- Caffe在Windows上的搭建
- 使用比较器对Treemap按照key进行排序
- Kotlin 学习资源
- ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: NO) Mac解决方案
- zxing二维码生成扫描,识别二维码图片,长按识别二维码调用方便简洁