7
13
2015
3

BZOJ 1855 股票交易

Description

最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他 总结出了股票行情的一些规律。 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价为每股APi,第i天的股票卖出价为每股BPi(数据保证对于每 个i,都有APi>=BPi),但是每天不能无限制地交易,于是股票交易所规定第i天的一次买入至多只能购买ASi股,一次卖出至多只能卖出BSi 股。 另外,股票交易所还制定了两个规定。为了避免大家疯狂交易,股票交易所规定在两次交易(某一天的买入或者卖出均算是一次交易)之间,至少要间隔W天,也就 是说如果在第i天发生了交易,那么从第i+1天到第i+W天,均不能发生交易。同时,为了避免垄断,股票交易所还规定在任何时间,一个人的手里的股票数不 能超过MaxP。 在第1天之前,lxhgww手里有一大笔钱(可以认为钱的数目无限),但是没有任何股票,当然,T天以后,lxhgww想要赚到最多的钱,聪明的程序员 们,你们能帮助他吗?
 
动规,对于f(i,j)表示第i天有j张股票的最大钱数。
转移方式有三种:
                           f(i,j)=f(i-1,j)(不买不卖)
                           f(i,j)=f(i-w,k)-(k-j)*ap(买入)=》f(i-w,k)-k*ap+j*ap
                           f(i,j)=f(i-w,k)+(j-k)*bp(卖出)=》f(i-w,k)-k*bp+j*bp
                        对于  f(i-w,k)-k*ap  可以用一个优先队列维护于是就可以O(1)求出来;
 
/**************************************************************
    Problem: 1855
    User: 1115825064
    Language: C++
    Result: Accepted
    Time:376 ms
    Memory:16976 kb
****************************************************************/
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
const int N=2004,INF=0x3fffffff;
int t,maxp,w,f[N][N];
struct D{
    int x,y;
}q[N];
int head,tail;
int ans=0;
int main()
{
    //freopen("1.txt","r",stdin);
     
    scanf("%d%d%d",&t,&maxp,&w);
    for(int i=0;i<=t;++i)
        for(int j=0;j<=maxp;++j)
            f[i][j]=-INF;
    for(int i=1;i<=t;++i)
    {
        int ap,bp,as,bs,bj=0;
        scanf("%d%d%d%d",&ap,&bp,&as,&bs);
        for(int j=0;j<=as;++j)
            f[i][j]=-ap*j;
        for(int j=0;j<=maxp;++j)
            f[i][j]=max(f[i][j],f[i-1][j]);
        int k=i-w-1;
        if(k>=0)
        {
             head=0,tail=0;
             for(int j=0;j<=maxp;++j)
             {
                while(q[head].x<j-as&&head<tail) head++;
                while(q[tail-1].y<=f[k][j]+ap*j&&head<tail) tail--;
                q[tail].x=j,q[tail++].y=f[k][j]+ap*j;
                if(head<tail) f[i][j]=max(f[i][j],q[head].y-ap*j);
             }
             head=0,tail=0; 
             for(int j=maxp;j>=0;--j)
             {
                while(head<tail&&q[head].x>j+bs) head++;
                while(head<tail&&q[tail-1].y<=f[k][j]+bp*j)tail--;
                q[tail].x=j,q[tail++].y=f[k][j]+bp*j;
                if(head<tail) f[i][j]=max(f[i][j],q[head].y-bp*j);
             }
        }
        ans=max(ans,f[i][0]);
    }
    printf("%d",ans);
    return 0;
}
 
Category: 未分类 | Tags: | Read Count: 1635
Avatar_small
deep cleaning servic 说:
2021年8月30日 17:31

Are you currently searching for a trustworthy office cleaning supplier in Dubai? When yes, then we only at Crystal Moose are the ever-present spouse. We attempt to use the newest cleaning machinery to remove all obstinate stains within your office. We understand the value of creating a clean business office. It increases your self-assurance, not to cover that any clean a workplace improves productiveness. We plan an business office cleaning schedule according to your tastes. You are able to inform us of one's needs, and we will take that from right now there. Besides, our custom-made offices washing services enable us to fulfill your special cleaning wants.

Avatar_small
maid agency dubai 说:
2021年11月15日 22:39

Professionals assist by providing their information and experience to fresh franchisees. There is certainly ongoing support at the same time, including notifications, security and also safety treatments, meetings, any toll-free help line, world wide web, and industry operations and also evaluations. You can find instructional Digital video disks, a exclusive website, and also advanced education. Maid Brigade is specialized in making positive all franchises are usually successfully and also profitably work. The company manages advertising, and also sends fresh ads and also promotions to be able to each operation.

Avatar_small
monthly cleaning ser 说:
2023年10月04日 16:24

The particular artist uses a multi-stage process to generate paintings. As an example, the canvas should be painted having an initial coating of slender paint so that it has a straight tone together with which the specific painting can look very excellent.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com