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. [wikioi 1519]过路费(最小生成树+树链剖分)

    题目:http://www.wikioi.com/problem/1519/ 题意:给你一个连通的无向图,每条边都有权值,给你若干个询问(x,y),要输出从x到y的路径上边的最大值的最小值 分析:首先 ...

  2. [vijos1264]神秘的咒语(LCIS)

    描述身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底.据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法术, ...

  3. 编写高质量代码改善C#程序的157个建议[4-9]

    前言 本文首先亦同步到http://www.cnblogs.com/aehyok/p/3624579.html.本文主要来学习记录一下内容: 建议4.TryParse比Parse好 建议5.使用int ...

  4. Linq之IQueryable接口与IEnumberable区别

    IEnumerable接口 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代.也就是说:实现了此接口的object,就可以直接使用foreach遍历此object: IEnumerable 包含 ...

  5. AngularJs-指令和控制器交互

    前言: 前段时间我们学习了angular的指令,他通过ECMA的方式创建元素,可以让我们共用这些元素,我们也知道可以通过 link的方法给这个指令添加一些动作事件,本节,我们将写入和让angular的 ...

  6. 每天一个linux命令(25):df 命令

    linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...

  7. “耐撕”团队 2016.03.30 站立会议

    1. 时间: 16:45--17:05  总计:20分钟 2. 成员: Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...

  8. 手工部署项目到tomcat

    正确的方法是,在eclipse里面的项目伤右键,然后Export,然后在弹出的框当中选择导出类型,这里选择web下面的WAR file,然后下一步,选择导出到哪里,然后把导出的war文件放到tomca ...

  9. tomcat虚拟路径的几种配置方法

    一般我们都是直接引用webapps下面的web项目,如果我们要部署一个在其它地方的WEB项目,这就要在TOMCAT中设置虚拟路径了,Tomcat的加载web顺序是先加载 $Tomcat_home$\c ...

  10. 利用less监视模式实时预览样式刷新浏览器

    [前言]此处介绍的方法只是我个人的用法,相信大家有更好更简洁的方式. 上次写到利用LiveReload解放F5.而且LiveReload可以编辑sass/less/stylus.但是可惜发现LiveR ...