题目描述

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
5
3
4
2
10
输出样例#1: 复制

9

说明

【样例说明】

贝茜在第1分钟内选择跑步(跑了5米),在第2分钟内休息,在第3分钟内跑步(跑了4米),剩余的时间都用来休息。因为在晨跑结束时贝茜的疲劳度必须为0,所以她不能在第5分钟内选择跑步

//#include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = a; i >= (b); i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
const int M=;
// name*******************************
int n,m;
int d[];
int f[][];
// function****************************** //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout); cin>>n>>m;
For(i,,n)
cin>>d[i]; For(i,,n)
{
f[i][]=f[i-][];
For(j,,min(i,m))
{ f[i][]=max(f[i][],f[i-j][j]);
f[i][j]=f[i-][j-]+d[i];
}
} cout<<f[n][]; return ;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
const int maxn = ;
#define mod 100003
const int N=; // name*******************************
int f[][];
int n,m;
int a[]; // function****************************** //***************************************
int main()
{
// freopen("test.txt", "r", stdin); cin>>n>>m;
For(i,,n)
{
scanf("%d",&a[i]);
}
For(i,,n)
{
if(i>=)
f[i][]=max(f[i-][],f[i][]);
For(j,,min(i,m))
{
f[i+j][]=max(f[i+j][],f[i][j]);
f[i+][j+]=max(f[i+][j+],f[i][j]+a[i+]);
}
}
cout<<f[n][]; return ;
}

最新文章

  1. react+redux教程(四)undo、devtools、router
  2. 理论基础知识之————KB Kb Kbps 相关单位的区别和换算
  3. XF 文档 - Element Framework Doc
  4. listview 的适配器 getview 随着软件健盘显示和隐藏,出现多个空的position问题
  5. NOSQL Mongo入门学习笔记 - 数据的基本插入(二)
  6. freemaker分页备忘
  7. hdu1047(Java)大数相加
  8. 20160420javaweb之文件上传和下载
  9. SQLSERVER异机备份
  10. JavaSE教程-02Java基本语法-思维导图
  11. 一款优秀的JavaScript框架—AngularJS
  12. pickle使用及案例
  13. C语言经典算法 - 多维矩阵转一维矩阵的代码
  14. Spring Cloud中的负载均衡策略
  15. Navicat Premium 12.0.29 / 12.1.5.0安装与激活
  16. Razor视图基本语法
  17. django linux环境部署
  18. 【.NET 深呼吸】在 .net core app 中使用 Composition
  19. 利用原生JS实现网页1920banner图滚动效果
  20. 基于jQuery+HTML5加入购物车代码

热门文章

  1. grafana 安装- 曲线图展示每秒新增数据量
  2. 第二十天- 多继承 经典MRO 新式MRO super()
  3. android studio *.apk does not exist on disk
  4. Atitit.播放系统的选片服务器,包厢记时系统&#160;的说明,教程,维护,故障排查手册p825
  5. 请求包含(Include)和请求转发(Forward)
  6. 深入理解net core中的依赖注入、Singleton、Scoped、Transient(三)
  7. Eigen学习
  8. spring boot(11)-druid监控
  9. Vue2学习笔记:实例生命周期
  10. 【Kettle】1、简单介绍