一共有N段过程,每段过程里可以选择 快速跑、 匀速跑 和 慢速跑

对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量

选手一开始有M的能量,即能量上限

求通过全程的最短时间

定义DP[i][j] 为跨越第 i 个栏,剩余 j 点能量

动态转移方程

dp[i][j] = min(dp[i][j], dp[i-1][j-F1]+T1)    (Fast Mode)

dp[i][j] = min(dp[i][j], dp[i-1][j]+T2)     (Normal Mode)

dp[i][j] = min(dp[i][j], dp[i-1][j+F2]+T3)   (Slow Mode)

Source Code:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ;
const int INF = 0x3f3f3f3f ;
const int MAX = ; struct sc{
int t1, t2, t3, f1, f2;
}a[]; int n, m;
int dp[][]; int main(){
std::ios::sync_with_stdio(false);
int i, j, t, k, l, u, v, x, y, numCase = ;
cin >> t;
while(t--){
cin >> n >> m;
for(i = ; i < n; ++i){
cin >> a[i].t1 >> a[i].t2 >> a[i].t3 >> a[i].f1 >> a[i].f2;
}
memset(dp, 0x3f, sizeof(dp));
dp[][m] = ;
for(i = ; i < n; ++i){
for(j = ; j <= m; ++j){
if(j >= a[i].f1){
checkmin(dp[i + ][j - a[i].f1], dp[i][j] + a[i].t1);
}
if(j + a[i].f2 > m){
checkmin(dp[i + ][m], dp[i][j] + a[i].t3);
} else{
checkmin(dp[i + ][j + a[i].f2], dp[i][j] + a[i].t3);
}
checkmin(dp[i + ][j], dp[i][j] + a[i].t2);
}
}
int ans = INF;
for(i = ; i <= m; ++i){
checkmin(ans, dp[n][i]);
}
cout << ans << endl;
} return ;
}

ZOJ 2972 Hurdles of 110m 【DP 背包】的更多相关文章

  1. zoj 2972 - Hurdles of 110m

    题目:110米栏,运动员能够用三种状态跑,1状态耗体力且跑得快,2状态不消耗体力,3状态恢复体力且跑得慢. 体力上限是M,且初始满体力,如今想知到最小的时间跑全然程. 分析:dp,全然背包.题目是一个 ...

  2. TZOJ 1545 Hurdles of 110m(01背包dp)

    描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...

  3. zju 2972 Hurdles of 110m(简单的dp)

    题目 简单的dp,但是我还是参考了网上的思路,具体我没考虑到的地方见代码 #include<stdio.h> #include<iostream> #include<st ...

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

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

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

  6. ZOJ 3626(树形DP+背包+边cost)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3626 题目大意:树中取点.每过一条边有一定cost,且最后要回 ...

  7. ZOJ 3201 树形dp+背包(简单题)

    #include<cstdio> #include<vector> #include<cstring> #include<iostream> using ...

  8. ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪婪)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...

  9. 【TOJ 1545】Hurdles of 110m(动态规划)

    描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...

随机推荐

  1. yield return in C#

    Yield has two great uses It helps to provide custom iteration with out creating temp collections. It ...

  2. Python的安装和详细配置(转)

    Python是一种面向对象.解释型计算机程序设计语言.被认为是比较好的胶水语言.至于其他的,你可以去百度一下.本文仅介绍python的安装和配置,供刚入门的朋友快速搭建自己的学习和开发环境.本人欢迎大 ...

  3. B - 楼下水题(扩展欧几里德)

    B - 楼下水题 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  4. Android中GPS简介及其应用

    GPS是Global Positioning System(全球定位系统)的简称,它的作用就是为全球的物体提供定位功能.GPS定位是一门高新技术,但对于Android程序员来说,开发GPS功能的应用程 ...

  5. JS中onload的各种使用

    1.最简单的调用方式 直接写到html的body标签里面,如: <html> <body onload="func()"> </body> &l ...

  6. 使用LiveWriter发布Orchard博客

    我们可以Windows Live Writer来发布Orchard博客 在Dashboard–> Modules菜单找到 Remote Blog Publishing 模块.点击 Enable ...

  7. CAEmitterLayer 粒子发射器

    在iOS 5中,苹果引入了一个新的CALayer子类叫做CAEmitterLayer.CAEmitterLayer是一个高性能的粒子引擎,被用来创建实时例子动画如:烟雾,火,雨等等这些效果. CAEm ...

  8. java之路径

    在学习java的过程中经常遇见关于路径的问题:到底是使用绝对路径还是相对路径? 个人推荐使用相对路径,如果是使用绝对路径,到后期项目发布的时候会出现许多问题. 那么相对路径怎么用来: 一. Syste ...

  9. JavaSE学习总结第01天_Java概述

      01.01 计算机概述 计算机(Computer):全称电子计算机,俗称电脑. 是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备. 由硬件和软件所组成,没有安装任何软件的计算机称 ...

  10. Java安全机制之泛型(JDK1.5)

    泛型,类型安全机制. 好处: 1.将运行时期出现问题ClassCastException转移到了编译时期,方便解决问题,减少运行时期的问题,有利于程序的健壮性. 2.避免了强制转换的麻烦 泛型格式: ...