标签:单调队列 put 间隔 microsoft etc 一段 cpp 学习 ==
对于30%的数据,0 < =W 对于50%的数据,0 < =W 对于100%的数据,0 < =W
对于所有的数据,1 < =BPi < =APi < =1000,1 < =ASi,BSi < =MaxP
题解:比较傻的题。
用f[i][j]表示到了第i天,手里持有j个股票的最大收益。转移时用单调队列优化一下即可。
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,m,w,h,t,pa,pb,la,lb,ans;
int f[2010][2010],s[2010],s1[2010],s2[2010],q[2010];
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<‘0‘||gc>‘9‘) {if(gc==‘-‘) f=-f; gc=getchar();}
while(gc>=‘0‘&&gc<=‘9‘) ret=ret*10+(gc^‘0‘),gc=getchar();
return ret*f;
}
int main()
{
n=rd(),m=rd(),w=rd()+1;
int i,j;
for(i=1;i<=m;i++) s[i]=-1<<25;
for(i=1;i<=n;i++)
{
pa=rd(),pb=rd(),la=rd(),lb=rd();
if(i>w) for(j=0;j<=m;j++) s[j]=max(s[j],f[i-w][j]);
for(h=1,t=j=0;j<=m;j++)
{
while(h<=t&&q[h]<j-la) h++;
while(h<=t&&s[q[t]]+q[t]*pa<=s[j]+j*pa) t--;
q[++t]=j;
f[i][j]=s[q[h]]-(j-q[h])*pa;
}
for(h=1,t=0,j=m;j>=0;j--)
{
while(h<=t&&q[h]>j+lb) h++;
while(h<=t&&s[q[t]]+q[t]*pb<=s[j]+j*pb) t--;
q[++t]=j;
f[i][j]=max(f[i][j],s[q[h]]+(q[h]-j)*pb);
}
ans=max(ans,f[i][0]);
}
printf("%d",ans);
return 0;
}//5 2 0 2 1 1 1 2 1 1 1 3 2 1 1 4 3 1 1 5 4 1 1
【BZOJ1855】[Scoi2010]股票交易 DP+单调队列
标签:单调队列 put 间隔 microsoft etc 一段 cpp 学习 ==
原文地址:http://www.cnblogs.com/CQzhangyu/p/7859183.html