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 ...
随机推荐
- Dependency Walker使用说明
Dependency Walker使用说明 标签: dllexewindowsvbqq工具 2010-03-29 11:10 25175人阅读 评论(22) 收藏 举报 分类: 基本常识(45) ...
- EPiServer 简单项目总结
国内用到的EPiServer应该不多,所以记录点用到过的东西,以便分享 1.EPiServer office site http://www.episerver.com/ 2.EPiServer CM ...
- JavaEE Tutorials (27) - Java EE的并发工具
27.1并发基础427 27.1.1线程和进程42827.2并发工具的主要组件42827.3并发和事务42927.4并发和安全43027.5jobs并发示例430 27.5.1运行jobs示例4302 ...
- UML_交互图
交互图(Interaction Diagram)用来描述系统中的对象是如何进行相互作用的.即一组对象是如何进行消息传递的. 当交互图建模时,通常既包括对象(每个对象都扮演某一特定的角色),又包括消息( ...
- PHP转码函数
解决中文乱码问题,数据库使用sql server ,是gbk编码,所以在存储和前台显示时都要转码. function cn_convert2web($str){ return iconv('gbk', ...
- QT 绘制按钮 paintEvent enterEvent leaseEvent mouseEvent
案例2:绘制按钮 main.cpp #include<QApplication> #include “demoWidget.h” int main(int args , int arg ...
- 关于select
select 1与select * 的区别:“selelct 常量 from 表名” 对应所有行,返回的永远只有一个值,即常量 ,所以一般只用来判断是否有表记录:而“select * from 表名” ...
- Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS
由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动 ...
- swift学习二:基本的语法
声明本文转载自:http://www.cocoachina.com/applenews/devnews/2014/0603/8653.html Swift是什么? Swift是苹果于WWDC 2014 ...
- 好用的侧边栏菜单/面板jQuery插件
我想大家都用过一些APP应用,它们的菜单展示是以侧边栏滑动方式展现,感觉很新鲜,而现在网页设计也是如此,不少网站也效仿这样的方式来设计.使用侧边栏的好处就是可以节约空间,对于一些内容多或者喜欢简约的网 ...