[USACO08JAN]跑步Running dp
题目描述
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.
奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= N <= 10,000)分钟的晨跑。在每分钟的开始,贝茜会选择下一分钟是用来跑步还是休息。
贝茜的体力限制了她跑步的距离。更具体地,如果贝茜选择在第i分钟内跑步,她可以在这一分钟内跑D_i(1 <= D_i <= 1,000)米,并且她的疲劳度会增加1。不过,无论何时贝茜的疲劳度都不能超过M(1 <= M <= 500)。如果贝茜选择休息,那么她的疲劳度就会每分钟减少1,但她必须休息到疲劳度恢复到0为止。在疲劳度为0时休息的话,疲劳度不会再变动。晨跑开始时,贝茜的疲劳度为0。
还有,在N分钟的锻炼结束时,贝茜的疲劳度也必须恢复到0,否则她将没有足够的精力来对付这一整天中剩下的事情。
请你计算一下,贝茜最多能跑多少米。
输入输出格式
输入格式:
第1行: 2个用空格隔开的整数:N 和 M
第2..N+1行: 第i+1为1个整数:D_i
输出格式:
输出1个整数,表示在满足所有限制条件的情况下,贝茜能跑的最大距离
输入输出样例
说明
【样例说明】
贝茜在第1分钟内选择跑步(跑了5米),在第2分钟内休息,在第3分钟内跑步(跑了4米),剩余的时间都用来休息。因为在晨跑结束时贝茜的疲劳度必须为0,所以她不能在第5分钟内选择跑步
设 dp[ i ][ j ] 表示 第 i 分钟 疲劳度为 j 时的最大值;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int dp[100004][520];
int n, m;
int d[maxn]; int main() {
//ios::sync_with_stdio(0);
rdint(n); rdint(m);
for (int i = 1; i <= n; i++)rdint(d[i]);
dp[1][0] = 0; dp[1][1] = d[1];
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= min(i, m); j++) {
if (j == 0) {
dp[i][0] = max(dp[i][0], dp[i - 1][0]);
}
else {
dp[i + j][0] = max(dp[i + j][0], dp[i][j]);
}
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + d[i + 1]);
}
}
cout << dp[n][0] << endl;
return 0;
}
[USACO08JAN]跑步Running dp的更多相关文章
- bzoj1613 / P1353 [USACO08JAN]跑步Running
P1353 [USACO08JAN]跑步Running 显然的dp 设$f[i][j]$表示进行到第$i$分钟时,$j$疲劳度下的最远距离,$d[i]$为第$i$分钟下能跑的距离 分类讨论 1.运动: ...
- [USACO08JAN]跑步Running
题目描述 The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ...
- luogu P1353 [USACO08JAN]跑步Running
题目描述 The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ...
- P1353 [USACO08JAN]跑步Running
题目描述 The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ...
- P1353_[USACO08JAN]跑步Running 我死了。。。
我死了...被绿题虐...看来我的水平有待提高...QWQ 好吧,就是跑步的时候只能从跑步的状态转移过来 休息的时候可以从上一次休息时转移过来,也可以从某次跑步的时转移过来,需要枚举从哪一个状态转移来 ...
- 洛谷 题解 P1353 【[USACO08JAN]跑步Running】
动态规划 状态 dp[i][j]表示第i分钟疲劳值为j的最大值 初始 全部都为一个最小值"0" 转移 考虑休息和走 如果当前疲劳值比时间要大,显然不可能出现这种情况 如果比时间小 ...
- luogu P1353 【[USACO08JAN]跑步Running】
USACO!!! 唉!无一例外又是母牛(终于知道美国的牧场养什么了) 今天的主人公是一个叫贝茜的公主病母牛(好洋气) 可是她叫什么和我们理解题好像没有什么关系 通过读题我们可以发现她有三个傲娇的地方 ...
- 洛谷P1353 USACO 跑步 Running
题目 一道入门的dp,首先要先看懂题目要求. 容易得出状态\(dp[i][j]\)定义为i时间疲劳度为j所得到的最大距离 有两个坑点,首先疲劳到0仍然可以继续疲劳. 有第一个方程: \(dp[i][0 ...
- Noip2016day1 天天爱跑步running
题目描述 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.«天天爱跑步»是一个养成类游戏,需要玩家每天按时上线,完成打卡任务. 这个游戏的地图可以看作一一棵包含 个结点 ...
随机推荐
- codeforces 653C C. Bear and Up-Down(乱搞题)
题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- RouterOS(ROS)简单限速/单IP限速脚
暂无评论 有时企业环境,或个人使用环境需要针对不同IP设置较多条不同限速,可以使用以下脚本批量处理后,再针对性的修改. *脚本说明:“2 to 254”定义要设置受限IP的起始,后面“192.168. ...
- C语言逗号运算符和逗号表达式
在C语言中逗号","也是一种运算符,称为逗号运算符. 其功能是把两个表达式连接起来组成一个表达式, 称为逗号表达式.其一般形式为:表达式1,表达式2 其求值过程是分别求两个表达式的 ...
- Mybatis generator配置文件及说明
项目采用sring mvc + mybatis 组合,这里简单介绍下mybatis的应用: 我的IDE是STS(Spring + Tool + Suite), 安装Mybatis Generator插 ...
- JavaScript-Tool-富文本:UEditor
ylbtech-JavaScript-Tool-富文本:UEditor UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协 ...
- UDK编辑器 49条小提示
转自:http://www.cnblogs.com/hmxp8/archive/2012/02/09/2343674.html Very Helpful~ 01. First time using t ...
- PHP二维数组,根据多个字段来排序
如果是最最常见的二维数组排序, 大多数情况下也只用到二维: 用php内置函数 array_multisort( ) 是最简单的: <?php 假设, $arr 是一个二维数组, $arg1是取 ...
- 调试opencv调用摄像头程序时碰到的问题
昨天晚上想把opencv学习笔记整理一下,当跑opencv调用摄像头的程序的时候老是出现Assertion failed (size.width>0 && size.height ...
- js中Function方法
function.apply(thisArg,argArray) apply方法调用function,传递一个会绑定到this上的对象和一个可选的数组作为参数. apply方法被用在apply调用模式 ...
- EchoServer和EchoClient模型的改进1之多线程
在之前的EchoServer模型个EchoClient模型中,客户端和服务端只是单纯的一一对应的关系,如果存在多个客户端和一个服务端,这就需要具体处理了.在这里我们明显想到的第一种方案是使用多线程处理 ...