ZOJ3741 Eternal Reality DP

在学园都市里面,有6种等级的能力者,现在有n场比赛,参赛顺序已经规定,当参赛者的等级达到了比赛最低要求时得到1分,在比赛中可以使用等级提升器在【i,i+x-1】这几场比赛中提升一级,但是有副作用,在【i+x,i+x+y-1】这几场比赛中等级变为0 , 当药效结束后,可以再次使用。这里要注意的是等级5无法提升到到等级6

当 p ==5 时 最优的得分就是不用药的情况下能够拿到的分

当p<5时

用s1(i)表示到第i场比赛为止,不用药等得到多少分

用s2(i)表示到第i场比赛为止,用药可以额外得到多少分

用s3(i)表示到第i场比赛为止,有多少场能力要求为0

用f(i)表示到第i场比赛为止,最优拿多少分


f(i)=max(f(i-1)+s1(i)-s(i-1),f(i-x-y)+s1(i-y)-s1(i-x-y)+s2(i-y)-s2(i-x-y)+s3(i)-s3(i-y)))

注意要将f(1) ..... f(x+y-1)预处理出来

并且注意递推的时候将比赛场次延长到n+x+y(上述地推公式假设药效一定在i或者i之前结束)



Eternal Reality

Time Limit: 2 Seconds       Memory Limit: 65536 KB

In Academy City, most students have special abilities. Such as RailgunTeleportTelekinesisAIM Stalker and so on. Here, AIM (An Involuntary Movement) is a term used to refer to the phenomenon in which an esper involuntarily produces an invisible energy field around the esper. Different students have different type of AIM dispersion field, so they also have different level of abilities.

Of course, a higher level students can often deal with more issues than a lower level students. To classify the students in Academy City, there are 7 levels in total:

LevelTermDescription
Level 0Person with No PowersMost students of this level can't keep up at school. They might possess some degree of power, but unable to truly control it.
Level 1Person with Low PowersPowers of the degree to bend a spoon, many students belong here.
Level 2Person with Unusual PowersJust like Level 1, powers are not very useful in everyday life.
Level 3Person with Strong PowersThe degree when powers are considered convenient in everyday life, ability-wise this is the Level when one starts to be treated as part of the elite.
Level 4Person with Great PowersPowers of an extent that their owner acquires tactical value of a military force.
Level 5Person with Super PowersPowers of an extent that their owner can fight alone against a military force on equal terms.
Level 6Person with Absolute PowersPowers of an extent that they're considered immeasurable. However, no one can achieve this level, even with the help ofLevel Upper (it has no effect on persons with super powers). Since this, many institutions have been doing long-term researches about it, such as the Radio Noise Project.

You are a student of level L in Academy City and you are going to take part in a sports competition. The competition consists of N consecutive matches. If you want to get a point in the i-th match, your must reach at least Ai level. According to the rules, you must compete in all matches one by one.

To tell the truth, it won't be easy to compete with so many high-level opponents. Fortunately, you got a special item called Level Upper. Generally, it can increase your level by 1 for a short time. If you use the Level Upper before the i-th match, it's effect will last during the matches [i, i + X - 1]. But it also has a side effect that will make your level become 0 during the matches [i + X, i + X + Y - 1]. After the side effect ends, your level will return to L and you can use the Level Upper again.

Please calculate the maximal points you can get if you properly use the Level Upper.

Input

There are multiple test cases (plenty of small cases with several large cases). For each test case:

The first line contains four integers L (0 <= L <= 5), NX and Y (1 <= NXY <= 100). The next line contains N integers Ai (0 <= Ai <= 6).

Output

For each test case, output the maximal points you can get.

Sample Input
3 6 1 2
1 3 4 5 6 4
Sample Output
4
Hint

Read the problem description carefully.


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

int a[400];
int sum1[400];
int sum2[400];
int sum3[400];
int f[400];
int p,n,x,y;
int main(){
    while(~scanf("%d%d%d%d",&p,&n,&x,&y)){
        memset(sum1,0,sizeof(sum1));
        memset(sum2,0,sizeof(sum2));
        memset(sum3,0,sizeof(sum2));
        for(int i=1;i<=n;i++){
            int tmp;
            scanf("%d",&tmp);
            a[i]=tmp;
            if(tmp<=p)
                sum1[i]=sum1[i-1]+1;
            else
                sum1[i]=sum1[i-1];
            if(tmp==p+1)
                sum2[i]=sum2[i-1]+1;
            else
                sum2[i]=sum2[i-1];
            if(tmp==0)
                sum3[i]=sum3[i-1]+1;
            else
                sum3[i]=sum3[i-1];
        }
        if(p==5){
            printf("%d\n",sum1[n]);
            continue;
        }
        for(int i=n+1;i<=n+y+x;i++)
        {
            sum1[i]=sum1[i-1];
            sum2[i]=sum2[i-1];
            sum3[i]=sum3[i-1];
        }
        memset(f,0,sizeof(f));
        for(int i=1;i<=x+y;i++){
            f[i]=sum1[i];
        }
        f[x+y]=max(f[x+y],sum1[x]+sum2[x]+(sum3[x+y]-sum3[x]));
        for(int i=x+y+1;i<=n;i++){
            int add=0;
            if(a[i]<=p) add=1;
            f[i]=max(f[i-1]+add,f[i-x-y]+(sum1[i-y]-sum1[i-x-y]+sum2[i-y]-sum2[i-x-y]+sum3[i]-sum3[i-y]));
        }
        for(int i=max(n+1,x+y+1);i<=n+x+y;i++)
            f[i]=max(f[i-1],f[i-x-y]+(sum1[i-y]-sum1[i-x-y]+sum2[i-y]-sum2[i-x-y]+sum3[i]-sum3[i-y]));
        printf("%d\n",f[n+x+y]);

    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值