zoukankan      html  css  js  c++  java
  • [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解决,而且并不一定要直接求出要求的那个函数,可以换个表达间接求出                                                                                                

  • 相关阅读:
    [转]How do I use variables in Oracle SQL Developer?
    [转]一张图理解prototype、proto和constructor的三角关系
    [转]ASP.NET Web API系列教程(目录)
    [转]解读ASP.NET 5 & MVC6系列(7):依赖注入
    [转]什么?你还不会写JQuery 插件
    [书目20170314]理解未来的7个原则
    java List.subList方法中的超级大陷阱
    MyBatis动态传入表名,字段名参数的解决办法---statementType用法
    lvs+keepalived和haproxy+heartbeat区别
    Nginx/LVS/HAProxy负载均衡软件的优缺点详解
  • 原文地址:https://www.cnblogs.com/wmrv587/p/3583562.html
Copyright © 2011-2022 走看看