E - Eternal Reality

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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 of Level 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<stdio.h>
#include<string.h> using namespace std; int flag1[]; // 第i关不用技能是否可行
int flag2[]; // 第i关用技能是否可行
int flag3[]; // 第i关是否为0
int flag[][]; // 表示第i关j状态是否可行
int dp[][]; // 第i关的状态为j的最大过关数 // 这里的状态范围为 [0, x+y] ,分为三类
// [0] 正常状态, [1,x] 使用技能+1状态,[x+1,x+y] 技能恢复中能力值为0状态 int max(int a, int b)
{
return a > b ? a : b;
} int main()
{
int l, n, x, y;
while(scanf("%d %d %d %d",&l, &n, &x, &y) == )
{
memset(flag1, , sizeof(flag1));
memset(flag2, , sizeof(flag2));
memset(flag3, , sizeof(flag3));
memset(flag, , sizeof(flag));
memset(dp, , sizeof(dp));
int tmp;
for(int i = ; i <= n; i++)
{
scanf("%d",&tmp);
if(l >= tmp) flag1[i] = ;
if(l + >= tmp && l != ) // 能力值为5,技能+1过关,不可行
{
flag2[i] = ;
}
if(tmp == ) flag3[i] = ;
}
flag[][] = ;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= x + y; j++)
{
if((j == || j == x + y) && flag[i-][j])
{
//如果前一个状态为 0 或 x+y 并且 前一关状态j可行
//那么下一个状态可以用技能到状态1或不用技能到状态0
dp[i][] = max(dp[i][], dp[i-][j] + flag1[i]);//不用技能
dp[i][] = max(dp[i][], dp[i-][j] + flag2[i]);//用技能
flag[i][] = flag[i][] = ;
}
else if(j > && j < x + y && flag[i-][j])
{
//当前状态为 >0 && <x+y 说明已经用过技能
//那么下一个状态只能为 [2, x+y] 范围内
//那么将前一个状态j可以分成 [1,x) 和 [x, x+y) 考虑
if(j < x)
{
dp[i][j+] = max(dp[i][j+], dp[i-][j] + flag2[i]); //必须用技能
}
else
{
dp[i][j+] = max(dp[i][j+], dp[i-][j] + flag3[i]); //技能冷却中,能力值为0
}
flag[i][j+] = ;
}
}
}
int ans = ;
for(int i = ; i <= x + y; i++)
{
ans = max(ans, dp[n][i]);
}
printf("%d\n",ans);
}
return ;
}

ZOJ3741 状压DP Eternal Reality的更多相关文章

  1. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  2. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  3. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  4. [NOIP2016]愤怒的小鸟 D2 T3 状压DP

    [NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...

  5. 【BZOJ2073】[POI2004]PRZ 状压DP

    [BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...

  6. bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)

    数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...

  7. HDU 1074 Doing Homework (状压dp)

    题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...

  8. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  9. 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP

    [BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...

随机推荐

  1. 第四课:seajs的模块编译_compile过程

    最近比较闲,我就讲下seajs的模块编译_compile过程. 这里紧接着第三课的例子来讲解.首先是a.js的编译 Module.prototype._compile = function() { 1 ...

  2. nginx 配置虚拟主机

    文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...

  3. iOS边练边学--父子控制器之自定义控制器的切换

    一.如图所示的界面,按钮One.Two.Three分别对应三个控制器的view,点击实现切换.个人感觉父子控制器的重点在于,控制器的view们之间建立了父子关系,控制器不建立的话,发生在view上面的 ...

  4. chrom_input_click

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. Struts2(二)---将页面表单中的数据提交给Action

    问题:在struts2框架下,如何将表单数据传递给业务控制器Action. struts2中,表单想Action传递参数的方式有两种,并且这两种传参方式都是struts2默认实现的,他们分别是基本属性 ...

  6. sort+awk+uniq三者结合使用

    (1)统计文件中出现次数最多的前10个单词 #ps -ef > ps.file #cat ps.file | awk ‘{print $1}’ | sort | uniq -c | sort - ...

  7. 40.Android之新手指引界面学习

    我们经常可以看到打开新App会有新手指引界面,类似蒙板效果今天来学习.原理其实很简单,设置一个透明Activity或者Dialog,然后修改其属性即可.由于实现比较简单,就贴一部分代码. 1.在And ...

  8. Looper

    /** * Class used to run a message loop for a thread. Threads by default do * not have a message loop ...

  9. Java Web 设置默认首页

    一.问题描述 这里所谓的默认首页,是指在访问项目根目录时(如 http://localhost:8080/zhx-web/ )展示的页面,通过在web.xml里配置 <welcome-file- ...

  10. mysql 为字段增加主键

    alter table 表名 add primary key(`字段`)