一共有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. Symfony框架系列----常用命令

    一.常用命令 从Entity操作数据库: app/console doctrine:database:create # 创建数据库 app/console doctrine:schema:update ...

  2. javascript 原型 和 原型链

    最近几天,好些新同事来问原型,原型链啥的.本身作为菜鸟的我好像也没有好好整理过这个,这里写写自己的理解. 原型 大家都知道,JavaScript 不包含传统的类继承模型,而是使用 prototype ...

  3. IPv6地址的ping、telnet等操作

    最近在研究https协议是如何传输数据的,用wireshark抓包分析,发现客户机和google网站在传输数据时使用了IPv6地址,于是相对ipv6地址测试下基本的功能. ping功能,直接使用pin ...

  4. NET Core Docker部署

    NET Core Docker部署 前言 在前面文章中,介绍了 ASP.NET Core在 macOS,Linux 上基于Nginx和Jexus的发布和部署,本篇文章主要是如何在Docker容器中运行 ...

  5. 使用libcurl POST数据和上传文件

    为了具有通用性,将文件的内容读到了fc变量中,fclen是fc的长度.fc也可以是任何其它内容.curl 是 libcurl句柄.演示省略了很多显而易见的步骤.   1. 普通的post请求,这里用c ...

  6. java代码发送JSON格式的httpPOST请求

    package com.test; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOE ...

  7. python中的迭代

    #迭代Python的for循环不仅可以用在list或tuple上,还可以作用在其他可迭代对象上. #list这种数据类型虽然有下标,但很多其他数据类型是没有下标的,但是,只要是可迭代对象,无论有无下标 ...

  8. java中只能有一个实例的类的创建

    Java中,如果我们创建一个类,想让这个类只有一个对象,那么我们可以 1:把该类的构造方法设计为private 2:在该类中定义一个static方法,在该方法中创建对象 package test; / ...

  9. html 5 废弃的标签和属性

    第一类:表现性元素 basefont big center font s strike tt u 建议用语义正确的元素代替他们,并使用CSS来确保渲染后的效果 第二类:框架类元素 因框架有很多可用性及 ...

  10. Apache+php+mysql+phpadmin搭建

    一,准备工具. httpd-2.4.12-win32-VC9.zip php-5.4.40-Win32-VC9-x86.zip phpMyAdmin-4.2.13.2-all-languages my ...