Cow Cycling
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 2516   Accepted: 1396

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

  1. 3 30 20

Sample Output

  1. 7

Hint

  1. [as shown in this chart:
  2.  
  3. leader E
  4.  
  5. pack total used this
  6.  
  7. time leader speed dist minute
  8.  
  9. 1 1 5 5 25
  10.  
  11. 2 1 2 7 4
  12.  
  13. 3 2* 4 11 16
  14.  
  15. 4 2 2 13 4
  16.  
  17. 5 3* 3 16 9
  18.  
  19. 6 3 2 18 4
  20.  
  21. 7 3 2 20 4
  22.  
  23. * = leader switch

Source

    我发现近期理解题意,真是该死,我理解成了最后仅仅能有一头牛通过,这样其它的牛除最后一头牛外最后的能量必须是负值。老是WA后。发现思路没错,就怀疑理解错题意。果然他要求的是仅仅要一头牛通过即可,求这头牛的最快时间,其它的牛不做要求。改了改初始话,AC了
题意:给定N头牛,每头牛的能量为E,距离为D,跑的时候假设是速度为X,则打头的牛的能量消耗为X*X/minute 其它的牛的能量消耗为X/minute 求当中一头牛到达终点时候,所用时间最少
思路:预处理出dp1[sta][end][e]:表示在能量为e的时候要跑的长度为sta,跑了end的时候用的时间最少
然后dfs+记忆化DP,枚举每头牛跑的长度。
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cmath>
  7. #define N 110
  8. #define INF 0x7ffffff
  9. using namespace std;
  10. int dp1[N][N][N];
  11. int dp[N][N][N];
  12. bool ch[N][N][N];
  13. int main()
  14. {
  15. //freopen("data.txt","r",stdin);
  16. int dfs(int n,int m,int k);
  17. int n,m,k;
  18. while(scanf("%d %d %d",&n,&m,&k)!=EOF)
  19. {
  20. for(int i=0;i<=k;i++)
  21. {
  22. for(int j=0;j<=i;j++)
  23. {
  24. for(int z = 0;z<=m;z++)
  25. {
  26. dp1[i][j][z]=INF;
  27. }
  28. }
  29. }
  30. for(int z= 0;z<=m;z++)
  31. {
  32. dp1[0][0][z] = 0;
  33. }
  34. for(int i=1;i<=k;i++)
  35. {
  36. for(int j=0;j<=m;j++)
  37. {
  38. dp1[i][0][j] = 0;
  39. }
  40. }
  41. for(int i=1;i<=k;i++)
  42. {
  43. for(int j=1;j<=i;j++)
  44. {
  45. for(int z=1;z<=m;z++)
  46. {
  47. for(int v=1;v*v<=z&&v<=j;v++)
  48. {
  49. dp1[i][j][z] = min(dp1[i][j][z],dp1[i-v][j-v][z-v*v]+1);
  50. }
  51. }
  52. }
  53. }
  54. memset(ch,false,sizeof(ch));
  55. dfs(n,k,m);
  56. if(dp[n][k][m]>=INF)
  57. {
  58. printf("0\n");
  59. }else
  60. {
  61. printf("%d\n",dp[n][k][m]);
  62. }
  63. }
  64. return 0;
  65. }
  66. int dfs(int n,int m,int k)
  67. {
  68. if(ch[n][m][k])
  69. {
  70. return dp[n][m][k];
  71. }
  72. if(n==1)
  73. {
  74. ch[n][m][k] = true;
  75. dp[n][m][k] = dp1[m][m][k];
  76. return dp1[m][m][k];
  77. }
  78. int Min = INF;
  79. for(int i=0;i<=m;i++)
  80. {
  81. if(dp1[m][i][k]!=INF)
  82. {
  83. int w = dfs(n-1,m-i,k-i);
  84. Min = min(Min,w+dp1[m][i][k]);
  85. }
  86. }
  87. ch[n][m][k] = true;
  88. dp[n][m][k] = Min;
  89. return Min;
  90. }

POJ 1946 Cow Cycling的更多相关文章

  1. POJ 1946 Cow Cycling(抽象背包, 多阶段DP)

    Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determi ...

  2. poj 1964 Cow Cycling(dp)

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

  3. [USACO2002][poj1946]Cow Cycling(dp)

    Cow CyclingTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2468 Accepted: 1378Description ...

  4. POJ 3045 Cow Acrobats (贪心)

    POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...

  5. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

  6. Cow Cycling 动态规划

    1552: Cow Cycling 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte总提交: 39            测试通过:20 描述 The ...

  7. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  8. POJ 3176 Cow Bowling(dp)

    POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...

  9. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

随机推荐

  1. fatal error C1189: #error : "No Target Architecture" 解决办法一

    在编译程序的时候发现报这个错误,在网上看到很多文章,说设置include路径,lib目录等等,都没有解决.最后调整了以下include文件的顺序,问题解决了.例如 从头文件a.h中截取的一段 type ...

  2. 【前端控件】JQuery datepicker 日期控件设置

    datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...

  3. 1. USB协议

    1.1 Packets USB总线上数据传输以包为基本单位,一个包含不同的域,但都要从同步域开始,然后跟踪一个包标识符PID(Packet Identifier),最终以包结束符EOP(End of ...

  4. localStorage使用总结(转载)

    localStorage使用总结  本文转载自:https://www.cnblogs.com/st-leslie/p/5617130.html(点击标题可跳转至原文) 一.什么是localStora ...

  5. 剑指offer——64和为s的数字

    题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. 题解 ...

  6. JSON.toJSONString()null值转“”

    public static void main(String[] s) { CybWmsCommoditiesVo cybWmsCommoditiesVo = new CybWmsCommoditie ...

  7. CDH5..4.7+phoenix实现查询HBase异常:java.sql.SQLException: ERROR 1102 (XCL02): Cannot get all table regions

    基础环境是用CM 安装的cdh5.4.7,phoenix使用的版本是phoenix-4.5.2-HBase-1.0-bin. 出现异常信息:java.sql.SQLException: ERROR 1 ...

  8. hbase启动的时候报:cat: /home/hadoop/hbase-0.94.6-cdh4.5.0/target/cached_classpath.txt: 没有那个文件或目录

    启动hbase的时候: -cdh4.5.0/bin$ hbase shell cat: /home/hadoop/hbase--cdh4.5.0/target/cached_classpath.txt ...

  9. D-Ubuntu中修改MySQL的默认数据集(client和server)

    Ubuntu16.04,MySQL5.7 1, sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 使用vim编辑MySQL的配置文件,不同版本的MySQL配置文件 ...

  10. 继续搞我的linux

    小程序研发已经告一段落,还是继续我的Linux研究.上次因为捣鼓那个fastab,结果吧虚拟机搞崩溃了.好吧,这次老子来装正式机,从机房拉来了一台破烂货,联想的老式服务器,开工吧. 用UltraISO ...