poj 3661 Running(区间dp)
Description
The cows are trying to become better athletes, so Bessie is running on a track for exactly N ( ≤ N ≤ ,) 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 . When she chooses to run in minute i, she will run exactly a distance of Di ( ≤ Di ≤ ,) and her exhaustion factor will increase by -- but must never be allowed to exceed M ( ≤ M ≤ ). If she chooses to rest, her exhaustion factor will decrease by for each minute she rests. She cannot commence running again until her exhaustion factor reaches . 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 : Two space-separated integers: N and M
* Lines ..N+: Line i+ contains the single integer: Di
Output
* Line : A single integer representing the largest distance Bessie can run while satisfying the conditions.
Sample Input
Sample Output
Source
题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度为0,当然,当疲劳度为0的时候也是可以继续选择休息的,求在n分钟后疲劳度为0所跑的最大距离
思路:dp[i][j]表示在第i分钟疲劳度为j的时候所跑的最大距离,dp[i][j]=dp[i-1][j-1]+d[i];这个转移,说的是,第i分钟选择跑步,当然,第i分钟可以选择不跑步,那么就是选择休息,题目说了,选择休息的话必须要休息到疲劳度为0才可以跑,那还有一点,当疲劳度为0了,还是选择继续休息呢?dp[i][0]=dp[i-1][0];
选择休息,那么疲劳度到0了,这一点的最大距离怎么做呢?dp[i][0]=max(dp[i][0],dp[i-k][k]) (0<k<=m&&i-k>0)
这样所有的状态都考虑完了,可以写代码了.......
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 10006
#define M 506
#define inf 1e12
int n,m;
int d[N],dp[N][M];//dp[i][j]表示i分钟j疲劳时的最大距离。
int main()
{
while(scanf("%d%d",&n,&m)==){
for(int i=;i<=n;i++){
scanf("%d",&d[i]);
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dp[i][j]=dp[i-][j-]+d[i];//在i分钟时选择跑
}
dp[i][]=dp[i-][];//如果在疲劳度为0时选择休息,=dp[i-1][0]
for(int j=;j<=m;j++){
if(i-j>=){
dp[i][]=max(dp[i][],dp[i-j][j]);//在i分钟选择休息到疲劳度为0
}
}
//dp[i][0]=dp[i-1][0];
}
printf("%d\n",dp[n][]); }
return ;
}
poj 3661 Running(区间dp)的更多相关文章
- POJ 2995 Brackets 区间DP
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间 ...
- POJ 1179 - Polygon - [区间DP]
题目链接:http://poj.org/problem?id=1179 Time Limit: 1000MS Memory Limit: 10000K Description Polygon is a ...
- POJ 1160 经典区间dp/四边形优化
链接http://poj.org/problem?id=1160 很好的一个题,涉及到了以前老师说过的一个题目,可惜没往那上面想. 题意,给出N个城镇的地址,他们在一条直线上,现在要选择P个城镇建立邮 ...
- POJ 1390 Blocks(区间DP)
Blocks [题目链接]Blocks [题目类型]区间DP &题意: 给定n个不同颜色的盒子,连续的相同颜色的k个盒子可以拿走,权值为k*k,求把所有盒子拿完的最大权值 &题解: 这 ...
- poj 2955"Brackets"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给你一个只由 '(' , ')' , '[' , ']' 组成的字符串s[ ], ...
- POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 56150 Accepted: 19398 Desc ...
- HOJ 1936&POJ 2955 Brackets(区间DP)
Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...
- IOI 98 (POJ 1179)Polygon(区间DP)
很容易想到枚举第一步切掉的边,然后再计算能够产生的最大值. 联想到区间DP,令dp[i][l][r]为第一步切掉第i条边后从第i个顶点起区间[l,r]能够生成的最大值是多少. 但是状态不好转移,因为操 ...
- POJ 1390 Blocks (区间DP) 题解
题意 t组数据,每组数据有n个方块,给出它们的颜色,每次消去的得分为相同颜色块个数的平方(要求连续),求最大得分. 首先看到这题我们发现我们要把大块尽可能放在一起才会有最大收益,我们要将相同颜色块合在 ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
随机推荐
- Android Studio中获取sha1证书指纹数据的方法
高德地图开发申请KEY的时候需要开发者提供SHA1证书指纹数据,在eclipse很容易就找到了,但是Android Studio很久也没找到,只能使用在网上看到的方法了,在Android Studio ...
- Sublime Text 3 Build 3047 32bit/64bit 简体中文安装破解版
Sublime Text 3 Build 3047 32bit/64bit 简体中文安装破解版 Sublime Text 3 Build 3047 32bit 简体中文安装破解版下载:http://y ...
- leetcode_question_104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- TestWriter自动化测试介绍
简介: TestWriter是上海博为峰结合多年为企业做测试服务的经验所研发的一款具有自主知识产权的自动化测试工具,为企业用户提供真正的低成本.高效率的自动化测试,引领软件测试自动化运用由技术层面向业 ...
- iOS 监听 出发 Home键 NSNotificationCenter UIApplicationWillResignActiveNotification
第一步: 创建2个NSNotificationCenter监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@sel ...
- 【OpenCV新手教程之十一】 形态学图像处理(二):开运算、闭运算、形态学梯度、顶帽、黑帽合辑
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/23184547 作者:毛星云(浅墨) ...
- Unity 利用NGUI2.6.3做技能冷却的CD效果
NGUI非常强大我们今天来学习一下,如何利用NGUI做技能冷却的CD效果.先导入NGUI的插件.没有的话这里有啊NGUI2.6.3下载地址: http://vdisk.weibo.com/s/KLqn ...
- 修改Chrome的User Agent的方法 真实有效
如何修改Chrome的User Agent: 通过网络上查找,修改Chrome的Usre Agent有3种方式,但有的方式是不起作用的. 给Chrome添加启动参数(有作用) 通过扩展-User-Ag ...
- struts 2 debug标签隐藏不显示
struts2 的标签debug在页面中应用,并且struts的配置文件中也设置为开发模式,但是这个标签却被隐藏了,究其原因,是因为页面中body元素生命了class,其样式覆盖了原来的样式. 比如: ...
- css系列教程--overflow min/maxheight content
outline:这只轮廓样式,与border类似.写法参考border. overflow/overflow-x/overflow-y:visible/hidden/scroll/auto/no-di ...