zoj 2972 - Hurdles of 110m
题目: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的更多相关文章
- ZOJ 2972 Hurdles of 110m 【DP 背包】
一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...
- zju 2972 Hurdles of 110m(简单的dp)
题目 简单的dp,但是我还是参考了网上的思路,具体我没考虑到的地方见代码 #include<stdio.h> #include<iostream> #include<st ...
- 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 ...
- 【TOJ 1545】Hurdles of 110m(动态规划)
描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...
- ZOJ-2972-Hurdles of 110m(线性dp)
Hurdles of 110m Time Limit: 2 Seconds Memory Limit: 65536 KB In the year 2008, the 29th Olympic ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- QDU_组队训练(ABEFGHKL)
A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- No resource found that matches the given name 'android:WindowTitle'
当你的androidAPI 由2.1版本更换成2.2版本时: res/vavlues/styles.xml中使用的android:WindowTitle会报以下异常, error: Error re ...
- (step 8.2.8)hdu 1079(Calendar Game)
题目大意是: 两个家伙在区域赛前夕闲的无聊,然后玩一种无限纠结的游戏,随即给定一个日期,每次只能移动day OR month.......... 而且如果下一个月没有当前day的话, 你就不能移动mo ...
- [置顶] 程序员面试之道(《程序员面试笔试宝典》)之看着别人手拿大把的offer,不淡定了怎么办?
不管是在哪里,不管发生什么事,不要随便放下自己. ——<当男人恋爱时> 很多求职者都会面临一个问题:别人手拿大把大把的offer了,而自己却是两手空空,别人签约之后已经过着“猪狗不如”的悠 ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- CLR和.Net对象
CLR和.Net对象生存周期 前言 1. 基础概念明晰* 1.1 公告语言运行时* 1.2 托管模块* 1.3 对象和类型* 1.4 垃圾回收器 2. 垃圾回收模型* 2.1 为什么需要垃圾回收* 2 ...
- Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)
设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);
- iOS学习——ViewController(六)
ViewController是iOS应用程序中重要的部分,是应用程序数据和视图之间的重要桥梁,ViewController管理应用中的众多视图. iOS的SDK中提供很多原生ViewControlle ...
- Swift教程之typealias代替OC的typedef
//MARK:-------swift中的typedef-------------- //使用 keyword定义类型别名,相似typedef typealias NSInteger = Int va ...
- 怎样查看apk须要支持的Android版本号
假设有一个apk,须要知道他最低安装支持的Android版本号是什么,应该怎样查看呢? 直接将apk后缀名改为rar或者zip,拉出AndroidManifest.xml?不行,AndroidMani ...
- 【翻译】ASP.NET Web API是什么?
原文 [翻译]ASP.NET Web API是什么? 说明:随微软ASP.NET MVC 4一起发布的还有一个框架,叫做ASP.NET Web API.目前国内关注这项技术的人似乎还很少,这方面的文章 ...