题目:110米栏,运动员能够用三种状态跑,1状态耗体力且跑得快,2状态不消耗体力,3状态恢复体力且跑得慢。

体力上限是M,且初始满体力,如今想知到最小的时间跑全然程。

分析:dp,全然背包。题目是一个物品体积可能为负数的背包,求背包就可以。

只是,由于物品体积可能是负数,所以无论哪个方向背包都有后效性,直接用二维避免后效性。

转移方程:F(i,j)= min(F(i-F1,j)+ T1,F(i-1,j)+ T2,F(i+F2,j)+T3)。

说明:(2011-09-19 01:23)。

#include <iostream>
#include <cstdlib> using namespace std; int F[ 111 ][ 111 ];
int T1[ 111 ];
int T2[ 111 ];
int T3[ 111 ];
int F1[ 111 ];
int F2[ 111 ]; int dp( int N, int M )
{
for ( int i = 0 ; i <= N ; ++ i )
for ( int j = 0 ; j <= M ; ++ j )
F[ i ][ j ] = 0xffffff; for ( int i = 0 ; i <= M ; ++ i )
F[ 0 ][ i ] = 0; for ( int i = 1 ; i <= N ; ++ i ) {
/* 第一状态 */
for ( int j = F1[ i ] ; j <= M ; ++ j )
if ( j <= M && F[ i ][ j-F1[ i ] ] > F[ i-1 ][ j ] + T1[ i ] )
F[ i ][ j-F1[ i ] ] = F[ i-1 ][ j ] + T1[ i ];
/* 第二状态 */
for ( int j = 0 ; j <= M ; ++ j )
if ( F[ i ][ j ] > F[ i-1 ][ j ] + T2[ i ] )
F[ i ][ j ] = F[ i-1 ][ j ] + T2[ i ];
/* 第三状态 */
for ( int j = 0 ; j <= M ; ++ j )
if ( F[ i ][ min(j+F2[ i ],M) ] > F[ i-1 ][ j ] + T3[ i ] )
F[ i ][ min(j+F2[ i ],M) ] = F[ i-1 ][ j ] + T3[ i ];
}
int Min = 0xffffff;
for ( int i = 0 ; i <= M ; ++ i )
if ( Min > F[ N ][ i ] )
Min = F[ N ][ i ];
return Min;
} int main()
{
int T,N,M;
while ( cin >> T )
while ( T -- ) {
cin >> N >> M;
for ( int i = 1 ; i <= N ; ++ i )
cin >> T1[ i ] >> T2[ i ] >> T3[ i ] >> F1[ i ] >> F2[ i ];
cout << dp( N, M ) << endl;
}
return 0;
}

zoj 2972 - Hurdles of 110m的更多相关文章

  1. ZOJ 2972 Hurdles of 110m 【DP 背包】

    一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...

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

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

  3. 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 ...

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

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

  5. ZOJ-2972-Hurdles of 110m(线性dp)

    Hurdles of 110m Time Limit: 2 Seconds      Memory Limit: 65536 KB In the year 2008, the 29th Olympic ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. QDU_组队训练(ABEFGHKL)

    A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. linux下抓取网页快照

    1.下载 https://code.google.com/p/wkhtmltopdf/downloads/detail?name=wkhtmltoimage-0.11.0_rc1-static-i38 ...

  2. Android 解屏幕锁与点亮屏幕

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  3. Perl 面向对象编程的两种实现和比较:

    <pre name="code" class="html">https://www.ibm.com/developerworks/cn/linux/ ...

  4. [Oracle]TRIGGER

    题外话: Oracle 的使用. 以前客户方用的是SQL SERVER,一直在用SQL SERVER,感觉SQL SERVER的用户体验非常好. 不管是开发环境的界面布局到SQL 的写法上,感觉写起来 ...

  5. python手记(27)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...

  6. 【Tips】Endnote导入IEEE Xplore文献方法《转载》

    1. 在IEEE XPlore中点击“Download Citation”: 2. 选中“Citation & Abstract”和“EndNote,Procite,RefMan”两个选项: ...

  7. Writing a Windows Shell Extension(marco cantu的博客)

    Writing a Windows Shell Extension This is a technical article covering the content of my last week s ...

  8. Delphi 拖放文件编程(覆盖WM_DROPFILES消息)

    unit Unit1; interface usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  ...

  9. Inverse Quadratic Interpolation (website)

    Inverse Quadratic Interpolation:  https://www.youtube.com/watch?v=0H7mVPTLF7Q : https://www.youtube. ...

  10. 52. 模版和设计元素——Lotus Notes的代码重用

    不论是理论上还是实用上,代码重用都是编程的一个重要议题.可以从两个角度来讨论代码重用. 一是逻辑上代码以怎样的方式被重用.既可以通过面向对象的思想普及以来耳熟能详的继承的方式.比如先建了一个车的基类, ...