zoukankan      html  css  js  c++  java
  • codeforces 922E Birds

    Apart from plush toys, Imp is a huge fan of little yellow birds!

    To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costi points of mana. However, for each bird summoned, Imp increases his mana capacity by B points. Imp summons birds one by one, he can summon any number from 0 to ci birds from the i-th nest.

    Initially Imp stands under the first tree and has W points of mana, and his mana capacity equals W as well. He can only go forward, and each time he moves from a tree to the next one, he restores X points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?

    Input

    The first line contains four integers n, W, B, X (1 ≤ n ≤ 103, 0 ≤ W, B, X ≤ 109) — the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.

    The second line contains n integers c1, c2, ..., cn (0 ≤ ci ≤ 104) — where ci is the number of birds living in the i-th nest. It is guaranteed that .

    The third line contains n integers cost1, cost2, ..., costn (0 ≤ costi ≤ 109), where costi is the mana cost to summon a bird from the i-th nest.

    Output

    Print a single integer — the maximum number of birds Imp can summon.

    Examples
    Input
    Copy
    2 12 0 4
    3 4
    4 2
    Output
    6
    Input
    Copy
    4 1000 10 35
    1 2 4 5
    1000 500 250 200
    Output
    5
    Input
    Copy
    2 10 7 11
    2 10
    6 1
    Output
    11
    Note

    In the first sample base amount of Imp's mana is equal to 12 (with maximum capacity also equal to 12). After he summons two birds from the first nest, he loses 8 mana points, although his maximum capacity will not increase (since B = 0). After this step his mana will be 4 of 12; during the move you will replenish 4 mana points, and hence own 8 mana out of 12 possible. Now it's optimal to take 4 birds from the second nest and spend 8 mana. The final answer will be — 6.

    In the second sample the base amount of mana is equal to 1000. The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.

    令$f[i][j]$表示前i棵树,选了j个的最大剩余

    转移$f[i][j]=max(min(f[i-1][k]+x,k*b+w)-(j-k)*cost[i])$

    枚举j和k就行了,转移要是合法状态,即不小于0

    最多也就是$O(10^4*10^4)$

    但大多数情况远远达不到

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 typedef long long lol;
     8 lol f[1001][10001],w,b,x,v[1001],inf;
     9 int c[1001],sum[1001],n;
    10 int main()
    11 {
    12     int i,j,k;
    13     cin>>n>>w>>b>>x;
    14     for (i=1; i<=n; i++)
    15     {
    16         scanf("%d",&c[i]);
    17         sum[i]=c[i]+sum[i-1];
    18     }
    19     for (i=1; i<=n; i++)
    20     {
    21         scanf("%lld",&v[i]);
    22     }
    23     memset(f,-127/2,sizeof(f));
    24     inf=f[0][0];
    25     f[0][0]=w;
    26     for (i=1; i<=n; i++)
    27     {
    28         for (j=0; j<=c[i]; j++)
    29         {
    30             for (k=j; k<=sum[i]; k++)
    31                 if (f[i-1][k-j]>=0)
    32                 {
    33                     f[i][k]=max(f[i][k],min(b*(k-j)+w,f[i-1][k-j]+x)-j*v[i]);
    34                 }
    35         }
    36     }
    37     for (i=sum[n]; i>=0; i--)
    38         if (f[n][i]>=0)
    39         {
    40             printf("%d",i);
    41             return 0;
    42         }
    43 }
  • 相关阅读:
    两数之和
    数组,链表,跳表
    第二讲:增长全景图
    三数之和
    第一讲:增长的本质
    移动零
    八十忆双亲+师友杂记
    java:从命令行接收多个数字,求和之后输出结果
    编程的精义读后感
    java语言基础第三讲作业
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8682112.html
Copyright © 2011-2022 走看看