[USACO2002][poj1946]Cow Cycling(dp)
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)的更多相关文章
- poj 1964 Cow Cycling(dp)
/* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那 ...
- POJ 3267:The Cow Lexicon(DP)
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- 【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 ...
- [luoguP1472] 奶牛家谱 Cow Pedigrees(DP)
传送门 一个深度为i的树可以由一个根节点外加两个深度为i-1的树组成,这就决定了DP该怎么写. 然而我真的没有想到. f[i][j]表示深度为i节点数为j的个数 sum[i][j]表示深度小于等于i节 ...
- [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...
- poj 3267 The Cow Lexicon(dp)
题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
随机推荐
- CSS纯样式实现箭头、对话框等形状
在使用第三方框架bootstrap的时候,本以为其是图片实现的小箭头,后来使用开发工具查看是用CSS来实现的,现记录如下: 之前都没仔细去观注过其原理,都是拿来使用,在实现小箭头之前需要了解下CSS的 ...
- 学习嵌入式Linux-选择iTOP-4412开发板
部分视频观看地址: [视频教程]iTOP-4412开发板之学习方法--致初学者 http://v.youku.com/v_show/id_XNzQ5MDA4NzM2.html [视频教程]三星Exyn ...
- 使用EntityFramework6完成增删查改和事务
使用EntityFramework6完成增删查改和事务 上一节我们已经学习了如何使用EF连接数据库,并简单演示了一下如何使用EF6对数据库进行操作,这一节我来详细讲解一下. 使用EF对数据库进行操作, ...
- Java实现事件机制
java中的事件机制的参与者有3种角色: 1.event object:事件状态对象,用于listener的相应的方法之中,作为参数,一般存在与listerner的方法之中 2.event sourc ...
- 第23章 SEH结构化异常处理(2)_编译器对系统SEH机制的封装
23.2 编译器层面对系统SEH机制的封装 23.2.1 扩展的EXCEPTION_REGISTRATION级相关结构:VC_EXCEPTION_REGISTRATION (1)VC_EXCEPTIO ...
- 仙人掌(cactus)
仙人掌(cactus) Time Limit:1000ms Memory Limit:64MB 题目描述 LYK 在冲刺清华集训(THUSC) !于是它开始研究仙人掌,它想来和你一起分享它最近研究的 ...
- table标签去除默认边框
table去除默认边框 1.在没有出去默认边框时,改变底部颜色,依然显示1px左右的白色边框 2.为table 加上 border="0" cellpadding="0& ...
- jenkins配置记录(1)--添加用户权限
前一阵子在线上部署了一套jenkins环境,作为线上代码发布平台使用.部署记录:http://www.cnblogs.com/kevingrace/p/5651427.html 下面重点记录下jenk ...
- POJ 1141 Brackets Sequence
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29502 Accepted: 840 ...
- 【原创】有关Silverlight DataGrid双击事件的分析 完整分析 代码与示例
公司项目用的silverlight,而且silverlight一些技术 资料比较少.所以分享出来 给大家参考参考. 有关Silverlight中DataGrid 双击事件 的代码 如下: 1. 前台x ...