POJ - 3661 Running(dp---背包)
题意:Bessie要运动N分钟,已知每一分钟可以跑的距离,每一分钟可选择跑或者不跑,若选择跑,疲劳度加1,但疲劳度不能超过M;若选择不跑,则每过一分钟,疲劳度减1,且只有当疲劳度减为0时可以继续跑。求运动N分钟后且疲劳度恰好为0时可以跑的最远距离。
分析:
1、dp[i][j]---第i分钟疲劳度为j时可以跑的最远距离。
2、dp[i][0] = dp[i - 1][0]---在第i分钟选择休息。
3、dp[i][0] = Max(dp[i][0], dp[i - j][j])---在第i-j分钟选择休息。
4、dp[i][j] = dp[i - 1][j - 1] + a[i]---第i分钟选择继续跑。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN];
int dp[MAXN][510];
int main(){
int N, M;
scanf("%d%d", &N, &M);
for(int i = 1; i <= N; ++i){
scanf("%d", &a[i]);
}
for(int i = 1; i <= N; ++i){
dp[i][0] = dp[i - 1][0];
for(int j = 1; j <= M; ++j){
if(i - j > 0){
dp[i][0] = Max(dp[i][0], dp[i - j][j]);
}
dp[i][j] = dp[i - 1][j - 1] + a[i];
}
}
printf("%d\n", dp[N][0]);
return 0;
}
POJ - 3661 Running(dp---背包)的更多相关文章
- poj 3661 Running(区间dp)
Description The cows are trying to become better athletes, so Bessie ≤ N ≤ ,) minutes. During each m ...
- POJ 3661 (线性DP)
题目链接: http://poj.org/problem?id=3661 题目大意:牛跑步.有N分钟,M疲劳值.每分钟跑的距离不同.每分钟可以选择跑步或是休息.一旦休息了必须休息到疲劳值为0.0疲劳值 ...
- POJ 1155 (树形DP+背包+优化)
题目链接: http://poj.org/problem?id=1155 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...
- poj 1947(树形DP+背包)
Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10663 Accepted: 4891 ...
- poj 3661 Running
题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度 ...
- 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp
题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...
- Fire (poj 2152 树形dp)
Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...
- URAL_1018 Binary Apple Tree 树形DP+背包
这个题目给定一棵树,以及树的每个树枝的苹果数量,要求在保留K个树枝的情况下最多能保留多少个苹果 一看就觉得是个树形DP,然后想出 dp[i][j]来表示第i个节点保留j个树枝的最大苹果数,但是在树形过 ...
- POJ 题目3661 Running(区间DP)
Running Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5652 Accepted: 2128 Descripti ...
随机推荐
- HTML学习第五天
HTML学习第五天 今天学HTML的实体.背景.布局 HTML布局的标签基本被淘汰frameset就被淘汰了,只有iframe依然存活,但是iframe可以被CSS给代替.下面就是一个练习的程序 &l ...
- linux(centos6.9)下rpm方式安装mysql后mysql服务无法启动
以下两种方式启动都报错:启动失败: [root@node03 ~]# service mysqld startMySQL Daemon failed to start.Starting mysqld: ...
- 【蓝桥】第八届C语言C组第7题 Excel地址(进制变形题,stack()简单使用)转载
标题: Excel地址 Excel单元格的地址表示很有趣,它使用字母来表示列号. 比如, A表示第1列, B表示第2列, Z表示第26列, AA表示第27列, AB表示第28列, BA表示第53列, ...
- Day7 - D - The Euler function HDU - 2824
The Euler function phi is an important kind of function in number theory, (n) represents the amount ...
- Day6 - 牛客203E
https://ac.nowcoder.com/acm/contest/203/E 埋坑不会做
- Angular2的双向数据绑定
什么是双向绑定 如图: 双向绑定.jpg 双向绑定机制维护了页面(View)与数据(Data)的一致性.如今,MVVM已经是前段流行框架必不可少的一部分. Angular2中的双向绑定 双向绑定, ...
- 第三篇:Vue指令
Vue指令 1.文本指令相关 v-*是Vue指令,会被vue解析,v-text="num"中的num是变量(指令是有限的,不可以自定义) v-text是原样输出渲染内容,渲染控制的 ...
- 如何将sql文件导入数据库
打开navicat.exe,点击打开数据库,右键-运行SQL文件,选中要运行的sql文件,确定后再点击表即可. 注意:此次改变后,源sql文件可以转移路径
- Sublime 一些常用快捷键
Sublime插件安装和使用-----------------------------最常用的1.新建文件-输入"html:xt"后 按"Ctrl+E键"或 & ...
- Vue核心知识一览
生命周期 beforeCreate : 数据观测 和 初始化事件还未开始 created : ...