$ HNOI2005 $ interstellar trade

Because the [Data Delete] too lazy to write interesting links

God \ (TM \) Ultra Rich. . .

Carefully observe a wave of questions surface, we find that the first question is a backpack, and ran it again just fine.

State \ (f [i] [j ] \) shows a front \ (i \) planets, sold \ (j \) t the largest trade volume.

But the best answer to the second question and the first question is related to a specific point in the transfer is first asked in Required.

On your second question, we set \ (f [i] [j ] \) represents the first \ (i \) planet, the remaining \ (j \) minimum cost of fuel.

Transfer enough to buy fuel and maintenance according to the two cases.

\(f[i][j]=max(f[i][j-1]+P_i,f[k][j+2]+F_i)\)

Obviously, this transfer is \ (n ^ 3 \) , weBy \ (yyb \) of the blogFound monotonic, with monotone can maintain the queue.

Note that the first encounter empty the queue points that must be transferred when asked.

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
    int f=1,w=0;char x=0;
    while(x<'0'||x>'9') {if(x=='-') f=-1; x=getchar();}
    while(x!=EOF&&x>='0'&&x<='9') {w=(w<<3)+(w<<1)+(x^48);x=getchar();}
    return w*f;
}
const int N=2e3+10;
int n,MF,ML,m,J,JJ,Q[N<<1][N];
int f[N][N<<1],Vis[N<<1],H[N<<1],T[N<<1];
struct Planet
{
    int Out,Mon;
    int Dis,Amt,Fix;
} p[N];
signed main(){
#ifndef ONLINE_JUDGE
    freopen("A.in","r",stdin);
#endif
    n=read();m=read(),MF=read(),ML=read();
    if(MF>(n<<1)) MF=n<<1;
    for(int i=1;i<=n;i++)
    {
        p[i].Out=read(),p[i].Mon=read();
        p[i].Dis=read(),p[i].Amt=read(),p[i].Fix=read();
    }
    for(int i=1;i<=n;i++)
        if(p[i].Dis-p[i-1].Dis>ML){puts("Poor Coke!");return 0;}
    memset(f,0xf3,sizeof(f));f[0][0]=0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=m;j++)
        {
            if(j>=p[i].Out)
                f[i][j]=max(f[i-1][j],f[i-1][j-p[i].Out]+p[i].Mon);
            f[i][j]=max(f[i-1][j],f[i][j]);
        }
    for(int i=1;i<=m;i++) if(f[n][i]>f[n][J]) J=i;
    int MYE=f[n][J];
    for(int i=n,Now=J;i;i--)
        if(f[i][Now]!=f[i-1][Now])
            Vis[i]=1,Now-=p[i].Out;
    memset(f,0x3f,sizeof(f));
    f[0][MF]=0;Q[MF][T[MF]++]=0;
    //H[MF]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=MF;j++)
        {
            if(p[i].Amt&&j) f[i][j]=min(f[i][j],f[i][j-1]+p[i].Amt);
            if(T[j+2]>H[j+2]) f[i][j]=min(f[i][j],f[Q[j+2][H[j+2]]][j+2]+p[i].Fix);
            if(Vis[i]) H[j]=0,T[j]=0;
            while(H[j]<T[j]&&f[Q[j][T[j]-1]][j]>=f[i][j]) T[j]--;
            Q[j][T[j]++]=i;
            while(H[j]<T[j]&&p[i+1].Dis-p[Q[j][H[j]]].Dis>ML) H[j]++;
        }
    for(int j=1;j<=MF;j++) if(f[n][j]<f[n][JJ]) JJ=j;
    f[n][JJ]>=1e9?puts("Poor Coke!"):printf("%lld %lld",MYE,MYE-f[n][JJ]);
}

Guess you like

Origin www.cnblogs.com/wo-shi-zhen-de-cai/p/11808915.html