题意: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---背包)的更多相关文章

  1. poj 3661 Running(区间dp)

    Description The cows are trying to become better athletes, so Bessie ≤ N ≤ ,) minutes. During each m ...

  2. POJ 3661 (线性DP)

    题目链接: http://poj.org/problem?id=3661 题目大意:牛跑步.有N分钟,M疲劳值.每分钟跑的距离不同.每分钟可以选择跑步或是休息.一旦休息了必须休息到疲劳值为0.0疲劳值 ...

  3. POJ 1155 (树形DP+背包+优化)

    题目链接: http://poj.org/problem?id=1155 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...

  4. poj 1947(树形DP+背包)

    Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10663   Accepted: 4891 ...

  5. poj 3661 Running

    题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度 ...

  6. 【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 ...

  7. Fire (poj 2152 树形dp)

    Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...

  8. URAL_1018 Binary Apple Tree 树形DP+背包

    这个题目给定一棵树,以及树的每个树枝的苹果数量,要求在保留K个树枝的情况下最多能保留多少个苹果 一看就觉得是个树形DP,然后想出 dp[i][j]来表示第i个节点保留j个树枝的最大苹果数,但是在树形过 ...

  9. POJ 题目3661 Running(区间DP)

    Running Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5652   Accepted: 2128 Descripti ...

随机推荐

  1. nested exception is javax.management.InstanceAlreadyExistsException: webservice:name=statFilter,type=StatFilter

    Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [ ...

  2. 空中网4k/5k月薪挑选大四实习生的线程题

    空中网4k/5k月薪挑选大四实习生的线程题 两年前,我们一个大四的学员去应聘空中网的实习生职位,空中网只给他出了三道线程题,拿回家做两天后再去给经理讲解,如果前两题做好了给4k月薪,第三道题也做出来的 ...

  3. 058、Java中定义一个没有参数没有返回值的方法

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  4. 002、创建第一个Java程序HelloWord

    代码如下: package TIANPAN; public class TestDemo { public static void main(String args[]) { System.out.p ...

  5. socket简单调用

    下载 Client using System; using System.Collections.Generic; using System.Linq; using System.Text; //导入 ...

  6. Python中语法糖及带参语法糖

    在python中,@符号常被称作语法糖(装饰器),在某函数定义时,用以包装该函数,以达到截取,控制该函数的目的. def d(f): print('d...') k=f #此处保留了传进来的原函数 f ...

  7. Easy Climb UVA - 12170 滚动dp +离散化+ 单调队列优化

    E.Easy Climb Somewhere in the neighborhood we have a very nice mountain that gives a splendid view o ...

  8. 【LeetCode】226. 翻转二叉树

    题目 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 本题同[剑指Offer]面试题27. 二叉树的镜 ...

  9. linux扩容空间,再扩容文件系统

    Linux磁盘空间进行扩容 参考博客 http://blog.csdn.net/dingchenxixi/article/details/50986472 http://blog.sina.com.c ...

  10. NAND厂商哭晕:减产也阻止不了跌价

    导读 NAND闪存价格已经连跌了6个季度,这让上游NAND厂商三星.东芝.美光等损失惨重,纷纷削减NAND产能.在群联台北电脑展上,群联公司董事长潘建成也预测NAND闪存价格已经跌破了成本,未来跌幅会 ...