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. Spark Streaming处理Flume数据练习

    把Flume Source(netcat类型),从终端上不断给Flume Source发送消息,Flume把消息汇集到Sink(avro类型),由Sink把消息推送给Spark Streaming并处 ...

  2. tomcat控制台运行窗口中文乱码

    启动tomcat时出来的运行窗口中文乱码, 如图所示:看得有点不舒服 解决方法:找到Tomcat安装路径下的 /conf/logging.properties 文件 文件末尾添加语句: java.ut ...

  3. 【RAC】安装rac的时候。报错checking for oracle home incompatibilities failed

    背景:由于oracle安装的时候中途出现了问题,解决过后,发现报错了 图形化安装的时候,有这个问题出现 解决办法: 删除安装过的所有缓存,和文件即可 1.删除ORACLE_BASE下的所有文件 2.删 ...

  4. Table controls and tabstrip controls

    本文转载自http://www.cnblogs.com/clsoho/archive/2010/01/21/1653268.html ONTROLS Syntax Forms Declaration ...

  5. Vijos-P1103题解【线段树】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: https://www.vijos.org/p/1103 题目描述: 一条马路从数轴0到L,每 ...

  6. Django-http协议

    Http协议:超文本传输协议(应用层程序).它是客户端和服务端请求和应答的标准.Http的请求响应模型:1.客户端连接到web服务器一个http客户端,与web服务器的http端口(默认是80)建立了 ...

  7. 聊聊.net应用程序的Docker镜像

    ​要在容器中运行.net应用程序,你需要在容器镜像中安装.net Framework或.net Core 运行时.这不是你需要自己管理的东西,因为微软提供的Docker镜像已经安装了运行时,你可以使用 ...

  8. Spring Security 实战干货:分布式对象SharedObject

    1. 前言 在上一篇我们对AuthenticationManager的初始化的细节进行了分析,其中里面有一段代码引起了不少同学的注意: ApplicationContext context = htt ...

  9. loj10008家庭作业

    题目描述 老师在开学第一天就把所有作业都布置了,每个作业如果在规定的时间内交上来的话才有学分.每个作业的截止日期和学分可能是不同的.例如如果一个作业学分为10 ,要求在6 天内交,那么要想拿到这 10 ...

  10. nginx 配置文件解读

    参考:链接 在微服务的体系之下,Nginx正在被越来越多的项目采用作为网关来使用,配合 Lua 做限流.熔断等控制 --源自 nginx Lua 脚本语言,用标准C语言编写并以源代码形式开放, 其设计 ...