在学园都市里面,有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之前结束)
In Academy City, most students have special abilities. Such as Railgun, Teleport, Telekinesis, AIM 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:
Level | Term | Description |
---|---|---|
Level 0 | Person with No Powers | Most students of this level can't keep up at school. They might possess some degree of power, but unable to truly control it. |
Level 1 | Person with Low Powers | Powers of the degree to bend a spoon, many students belong here. |
Level 2 | Person with Unusual Powers | Just like Level 1, powers are not very useful in everyday life. |
Level 3 | Person with Strong Powers | The 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 4 | Person with Great Powers | Powers of an extent that their owner acquires tactical value of a military force. |
Level 5 | Person with Super Powers | Powers of an extent that their owner can fight alone against a military force on equal terms. |
Level 6 | Person with Absolute Powers | Powers 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), N, X and Y (1 <= N, X, Y <= 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;
}