Cow Cycling
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 2468 Accepted: 1378
Description

The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the finish line as fast as possible.

Like everyone else, cows race bicycles in packs because that's the most efficient way to beat the wind. While travelling at x laps/minute (x is always an integer), the head of the pack expends x*x energy/minute while the rest of pack drafts behind him using only x energy/minute. Switching leaders requires no time though can only happen after an integer number of minutes. Of course, cows can drop out of the race at any time.

The cows have entered a race D (1 <= D <= 100) laps long. Each cow has the same initial energy, E (1 <= E <= 100).

What is the fastest possible finishing time? Only one cow has to cross the line. The finish time is an integer. Overshooting the line during some minute is no different than barely reaching it at the beginning of the next minute (though the cow must have the energy left to cycle the entire minute). N, D, and E are integers.
Input

A single line with three integers: N, E, and D
Output

A single line with the integer that is the fastest possible finishing time for the fastest possible cow. Output 0 if the cows are not strong enough to finish the race.
Sample Input

3 30 20
Sample Output

7
Hint

[as shown in this chart:

leader E

pack total used this

time leader speed dist minute

1 1 5 5 25

2 1 2 7 4

3 2* 4 11 16

4 2 2 13 4

5 3* 3 16 9

6 3 2 18 4

7 3 2 20 4

* = leader switch
Source

USACO 2002 February

题意:

【题意】

n(n<=20)头牛进行自行车比赛

需要跑d(d<=100)圈

每头牛初始有e(e<=100)的体力

流程按整分钟划分

比赛的时候若以x圈每分钟的速度前进,则领头牛每分钟消耗x*x的体力,其余牛每分钟消耗x的体力

若牛的体力小于x,则牛掉队

可在每分钟调换领头牛

只要有一头牛跑完要求圈数则算完成,问最快跑完需要几分钟

【分析】

挺好的一道dp

设f[i][j]表示一共i头牛,跑距离j要的最小时间

很显然i头牛的关系由i-1头牛递推得到

很容易得出f[i][j]=min(f[i-1][k]+w[E-k][j-k])

其中w[E-k][j-k]表示第i头牛还剩能量E-k(因为前面跑了距离k),而要跑剩下距离j-k所需要的最少时间

那么这个w[][]怎么破呢?

不妨设g[i][j]表示一头牛在i秒之内,剩余能量为j,所能跑到的最远距离

则易得g[i][j]=max(g[i-1][j-k^2]+k)

那么接下来根据g[i][j]就可以轻松的扫一遍得到w[][],完美解决!

总结:

1、思考一个dp问题的时候如果遇到某个函数求不出,可以考虑再次dp,即二重dp解决,而且并不一定要直接求出要求的那个函数,可以换个表达间接求出

[USACO2002][poj1946]Cow Cycling(dp)的更多相关文章

  1. poj 1964 Cow Cycling(dp)

    /* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那 ...

  2. POJ 3267:The Cow Lexicon(DP)

    http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

  3. 【POJ 3176】Cow Bowling(DP)

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

  4. 【USACO 2.3】Cow Pedigrees(DP)

    问n个结点深度为k且只有度为2或0的二叉树有多少种. dp[i][j]=dp[lk][ln]*dp[rk][j-1-ln],max(lk,rk)=i-1. http://train.usaco.org ...

  5. [luoguP1472] 奶牛家谱 Cow Pedigrees(DP)

    传送门 一个深度为i的树可以由一个根节点外加两个深度为i-1的树组成,这就决定了DP该怎么写. 然而我真的没有想到. f[i][j]表示深度为i节点数为j的个数 sum[i][j]表示深度小于等于i节 ...

  6. [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)

    传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...

  7. poj 3267 The Cow Lexicon(dp)

    题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...

  8. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  9. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

随机推荐

  1. Linux gcc命令

    一.简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objectiv ...

  2. 19 图形用户界面编程 - 《Python 核心编程》

  3. 2014 Super Training #10 D 花生的序列 --DP

    原题: FZU 2170 http://acm.fzu.edu.cn/problem.php?pid=2170 这题确实是当时没读懂题目,连样例都没想通,所以没做了,所以还是感觉这样散漫的做不好,有些 ...

  4. tomcat7 - 烫手山芋之热部署

    tomcat7部署,项目发布有很多种方式 1. 增量发布,把修改过得那些文件手动上传至tomcat,*.class *.xml 等等,这样的缺点非常大,需要断开tomcat,记住那些你修改过得文件,很 ...

  5. Spring MVC Spring MyBatis 整合 - 快速上手

    我个人比较喜欢写注释,在工作中对注释的重要性看的也比较高,所以大部分文字都在注释中,代码外的文字会写的偏少,关键能懂就行 先看一下整合后的工程目录(单工程,多工程以后会采用maven) 5个packa ...

  6. Android之数据存储----使用LoaderManager异步加载数据库

    一.各种概念: 1.Loaders: 适用于Android3.0以及更高的版本,它提供了一套在UI的主线程中异步加载数据的框架.使用Loaders可以非常简单的在Activity或者Fragment中 ...

  7. MonoDevelop line endings

    文件编码问题 这个让我头疼很久的问题,每次修改文件后,都会出现这个提示框. 解决办法 之前修改 D:\Program Files (x86)\Unity\Editor\Data\Resources\S ...

  8. IO流的练习1 —— 随机获取文本中的信息

    需求:一个文本中有几个名字,随机从中获取一个名字 分析: A:首先把文本中的数据读出 B:再把数据存储到集合中 C:产生一个随机的索引 D:打印出这个索引对应的值 public static void ...

  9. “display:block-inline形式的Span或Div中添加文字后,导致Span或Div排版掉落、错位”的原因及解决方法

    最近在使用3个span(或div)制作带圆角边框的按钮时,按照常识,把span的display设置成inline-block,这样就可以设置span的width和height了,很爽的~ 可是当我在中 ...

  10. angular常见坑洞

    由于版本不同,可能有些问题在某些版本下出现,某些版本下不出现. 指令不可平行(v1.3.2): 多个指令不能这样一个接着一个排下去: <div> <directive-one/> ...