Cow Cycling 动态规划

1552: Cow Cycling

时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte
总提交: 39            测试通过:20

描述

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.

输入

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

输出

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.

样例输入

3 30 20

样例输出

扫描二维码关注公众号,回复: 67067 查看本文章

7

提示

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

题意:有N头奶牛,每头奶牛的能量是E,现在有一个任务是跑完D圈,但是只要有一头奶牛完成这个任务就算通过。每次需要有一头奶牛领跑,其他的奶牛可以选择继续跟着跑或者离开队伍。领跑的奶牛能量

消耗是x*x laps/min,跟跑的能量消耗是x laps/min,然后让你计算最短需要多少时间完成任务。

题解:有N头奶牛,那么当N-1头奶牛都领跑过,那么最后一头奶牛去完成任务就成了。

状态:wxl[i][j][t],第i头奶牛跑 j 圈,消耗t能量所花费的最短时间。

状态转移方程:wxl[i+1][j][j]=min(wxl[i+1][j][j],wxl[i][j][t]);//换奶牛领跑不消耗时间      wxl[i][j+l][l*l+t]=min(wxl[i][j][t]+1,wxl[i][j+l][l*l+t]);

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 #define INF 0x3f3f3f3f
 4 int wxl[25][110][110];//存状态,第i头奶牛跑j圈,第i头奶牛消耗t所花费的最小时间
 5 int main()
 6 {
 7     ios::sync_with_stdio(false);
 8     cin.tie(0);cout.tie(0);//输入输出加速
 9     int n,e,d,i,j,t,l,sum=INF;
10     cin>>n>>e>>d;
11     for(i=0;i<=n;++i)for(j=0;j<=d;++j)for(t=0;t<=e;++t)wxl[i][j][t]=INF;
12     wxl[1][0][0]=0;
13     for(i=1;i<=n;++i)for(j=0;j<=d;++j)for(t=0;t<=e;++t)
14     {
15         if(wxl[i][j][t]==INF)continue;
16         for(l=1;l+j<=d&&l*l+t<=e;++l)wxl[i][j+l][l*l+t]=min(wxl[i][j][t]+1,wxl[i][j+l][l*l+t]);
17         wxl[i+1][j][j]=min(wxl[i+1][j][j],wxl[i][j][t]);//换奶牛领跑不消耗时间
18     }
19     for(i=0;i<=e;++i)sum=min(sum,wxl[n][d][i]);
20     cout<<sum<<endl;//当完不成任务时输出wxl[n][d][0];
21 }
22 //状态转移方程是wxl[i][t+l][l*l+t]=min(wxl[i][j][t]+1,wxl[i][t+l][l*l+t]);wxl[i+1][j][j]=min(wxl[i+1][j][j],wxl[i][j][t]);

猜你喜欢

转载自www.cnblogs.com/htmrc1/p/8947265.html