poj3661 Running
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的更多相关文章
- poj-3661 Running(DP)
http://poj.org/problem?id=3661 Description The cows are trying to become better athletes, so Bessie ...
- Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)
作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...
- Running Dubbo On Spring Boot
Dubbo(http://dubbo.io/) 是阿里的开源的一款分布式服务框架.而Spring Boot则是Spring社区这两年致力于打造的简化Java配置的微服务框架. 利用他们各自优势,配置到 ...
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- 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 ...
- teamviewer "TeamViewer Daemon is not running
执行下面的命令问题解决: # teamviewer --daemon enable enable Sat Jan :: CST Action: Installing daemon () for 'up ...
- 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 ...
- 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.解决 ...
- 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 ...
随机推荐
- kubernets之headless
一 认识headless服务 1服务以及服务的作用相信大家都已经耳熟能详了吗,服务接受请求,并且随机的将请求转发到相关联的任一pod来处理请求,但是考虑另外一种场景, 如果有客户端需要知道这个服务关 ...
- OGG类异常汇总
1.启动ogg后,进程不ABEND也不向前走 原因:ogg启动后,会收集表的统计信息耗费大量时间,导致进程不往前走 解决:在参数文件中加入 SQLEXEC 'alter session set OPT ...
- python协程爬取某网站的老赖数据
import re import json import aiohttp import asyncio import time import pymysql from asyncio.locks im ...
- SAP IDES登陆的short dump终于不见了
还记得这个IDES登陆的shortdump吗今天对内核从701_rel 升级到721,发现登陆的错误没了,看来721_rel内核支持的操作系统和数据库更多了,兼容性也更好了.
- const关键字:终于拥有真正的常量声明语句
本文首发于个人网站:const关键字:终于拥有真正的常量声明语句 你好,今天大叔想和你唠扯唠扯 ES6 新增的关键字 -- const.在说 const 关键字之前,大叔先和你唠唠大叔自己对 cons ...
- Windows下nginx设置开机自启动
第一步:下载 WinSW https://github.com/winsw/winsw/releases/download/v2.10.3/WinSW.NET4.exe 64位系统 https://g ...
- 解决JS获取中文参数出现的乱码问题
在代码中增加如下js函数: function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + " ...
- js 前端词典对象的属性和值读取
通常服务端返回比较奇葩的数据对象,不知道该怎么将这个对象转换为可用实体,想了很久,突发奇想想到了这么个方法. 需求是这样:企业有多个产品,产品有分为很几个种类.服务端有获取产品的接口,和单独获取产品种 ...
- 一步步使用SpringBoot结合Vue实现登录和用户管理功能
前后端分离开发是当今开发的主流.本篇文章从零开始,一步步使用SpringBoot结合Vue来实现日常开发中最常见的登录功能,以及登录之后对用户的管理功能.通过这个例子,可以快速入门SpringBoot ...
- SpringBoot 报错: Circular view path [readingList] 解决办法
spring boot报错: Circular view path [readingList]: would dispatch back to the current handler URL [/re ...