Description

The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ≤ N ≤ 10,000) minutes. During each minute, she can choose to either run or rest for the whole minute.

The ultimate distance Bessie runs, though, depends on her 'exhaustion factor', which starts at 0. When she chooses to run in minute i, she will run exactly a distance of Di (1 ≤ Di ≤ 1,000) and her exhaustion
factor will increase by 1 -- but must never be allowed to exceed M (1 ≤ M ≤ 500). If she chooses to rest, her exhaustion factor will decrease by 1 for each minute she rests. She cannot commence running again until her exhaustion factor reaches
0. At that point, she can choose to run or rest.

At the end of the N minute workout, Bessie's exaustion factor must be exactly 0, or she will not have enough energy left for the rest of the day.

Find the maximal distance Bessie can run.

Input

* Line 1: Two space-separated integers: N and M

* Lines 2..N+1: Line i+1 contains the single integer: Di

Output

* Line 1: A single integer representing the largest distance Bessie can run while satisfying the conditions.

 

Sample Input

5 2
5
3
4
2
10

Sample Output

9
这题用dp[i][j]表示前i秒疲劳值为j所能走的最远距离。注意一点:dp[i][j](j!=0)只能从dp[i-1][j-1]+a[i]转移过来,不能从dp[i-1][j+1]转移过来,因为如果上一秒的疲劳度大于1,那么这一秒的疲劳度必不为0,即这个转移过来的值不能继续走,而是要等到它为0时再走。                                                                                                                                                                            
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x7fffffff
int a[10060],dp[10060][505];
int main()
{
int n,m,i,j,maxx;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
memset(dp,-1,sizeof(dp));
dp[1][0]=0;
dp[1][1]=a[1];
for(i=2;i<=n;i++){
dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
for(j=1;j<=m;j++){
if(dp[i-1][j-1]!=-1){
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[i]);
}
if(i>j &&dp[i-j][j]!=-1){
dp[i][0]=max(dp[i-j][j],dp[i][0]);
}
}
}
printf("%d\n",dp[n][0]);
}
return 0;
}

poj3661 Running的更多相关文章

  1. poj-3661 Running(DP)

    http://poj.org/problem?id=3661 Description The cows are trying to become better athletes, so Bessie ...

  2. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  3. Running Dubbo On Spring Boot

    Dubbo(http://dubbo.io/) 是阿里的开源的一款分布式服务框架.而Spring Boot则是Spring社区这两年致力于打造的简化Java配置的微服务框架. 利用他们各自优势,配置到 ...

  4. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  5. IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551): java.net.SocketException

    学习Java Servlet时,从Wrox上下载了示例代码,准备run/debug时发现以下错误: Error running Tomcat 8.5.8: Unable to open debugge ...

  6. teamviewer "TeamViewer Daemon is not running

    执行下面的命令问题解决: # teamviewer --daemon enable enable Sat Jan :: CST Action: Installing daemon () for 'up ...

  7. mysql 有报错  ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

    sh-4.1# /etc/init.d/mysqld status ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql ...

  8. Errors occurred during the build. Errors running builder 'JavaScript Validator' on project

    1.问题:Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 2.解决 ...

  9. The network bridge on device VMnet0 is not running

    The network bridge on device VMnet0 is not running. The virtual machine will not be able to communic ...

随机推荐

  1. SonarQube学习(六)- SonarQube之扫描报告解析

    登录http://192.16.1.105:9000,加载项目扫描情况 点击项目名称,查看报告总览 开发人员主要关注为[问题]标签页. 类型 主要关注为bug和漏洞. 其中bug是必须要修复的,漏洞是 ...

  2. 【数据结构与算法】Java制作一个简单数组类

    bobo老师的玩转算法系列–玩转数据结构 简单记录 文章目录 不要小瞧数组 - 制作一个数组类 1 .使用Java中的数组 数组基础 简单使用 2.二次封装属于我们自己的数组 数组基础 制作属于我们自 ...

  3. C#中foreach的实现原理

    C#中foreach的实现原理 在探讨foreach如何内部如何实现这个问题之前,我们需要理解两个C#里边的接口,IEnumerable 与 IEnumerator. 在C#里边的遍历集合时用到的相关 ...

  4. SAP 修改表和表中数据

    平时修改表中数据的方式有一下几种: 1.一般就是通过SE11或者是SE16进去,找到那条记录,然后将模式变成EDIT,然后修改保存. 2.通过SQL语句在程序中实现数据库表的修改操作 3.通过SE16 ...

  5. ABAP 多表联合查询

    inner join(等值连接) 只返回两个表中联结字段相等的行left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录 ...

  6. MongoDB查询优化--explain,慢日志

    引入 与Mysql数据库一样,MongoDB也有自己的查询优化工具,explain和慢日志 explain shell命令格式 db.collection.explain().<method(. ...

  7. 与图论的邂逅05:最近公共祖先LCA

    什么是LCA? 祖先链 对于一棵树T,若它的根节点是r,对于任意一个树上的节点x,从r走到x的路径是唯一的(显然),那么这条路径上的点都是并且只有这些点是x的祖先.这些点组成的链(或者说路径)就是x的 ...

  8. 1V升压到3V的芯片,1V升压3.3V电路图

    1V升压到3V和1V升压3.3V的升压芯片? PW5100 是一款效率很大.低功耗.低纹波.高工作频率的 PFM 同步升压 DC/DC 变换器.输出电压可选固定输出值,从 3.0V,3.3V, 5.0 ...

  9. DDD的实体、值对象、聚合根的基类和接口:设计与实现

    1 前置阅读 在阅读本文章之前,你可以先阅读: 什么是DDD 2 实现值对象 值对象有两个主要特征:它们没有任何标识.它们是不可变的. 我们举个例子:小明是"浙江宁波"人,小红也是 ...

  10. Microsoft Windows的消息循环

    https://zh.wikipedia.org/wiki/Microsoft_Windows的訊息迴圈 微软视窗操作系统是以事件驱动做为程序设计的基础.程序的线程会从操作系统获取消息.应用程序会不断 ...