【HDOJ】2059 龟兔赛跑

经典DP,虽然参数比较多,不要被迷惑了。

 1 #include <stdio.h>
 2 
 3 #define MAXNUM 105
 4 #define INF    0xffffff
 5 
 6 double dists[MAXNUM];
 7 double dp[MAXNUM];
 8 
 9 double l;
10 int n;
11 double c, t, vr, vt1, vt2;
12 
13 int main() {
14     int i, j;
15     double tmp, t0, dist;
16 
17     while (scanf("%lf", &l) != EOF) {
18         scanf("%d%lf%lf", &n, &c, &t);
19         scanf("%lf%lf%lf", &vr, &vt1, &vt2);
20         for (i=1; i<=n; ++i)
21             scanf("%lf", &dists[i]);
22 
23         t0 = c / vt1;
24         dists[0] = dp[0] = 0;
25         dists[n+1] = l;
26 
27         for (i=1; i<=n+1; ++i) {
28             dist = dists[i] - dists[0];
29             if (dist < c)
30                 dp[i] = dist / vt1;
31             else
32                 dp[i] = t0 + (dist - c) / vt2;
33             for (j=1; j<i; ++j) {
34                 dist = dists[i] - dists[j];
35                 tmp = dp[j] + t;
36                 if (dist < c)
37                     tmp += dist / vt1;
38                 else
39                     tmp += t0 + (dist-c) / vt2;
40                 if (tmp < dp[i])
41                     dp[i] = tmp;
42             }
43         }
44         if (dp[n+1] > (l/vr))
45             printf("Good job,rabbit!\n");
46         else
47             printf("What a pity rabbit!\n");
48     }
49 
50     return 0;
51 }

 

posted on 2014-04-07 23:04  Bombe  阅读(261)  评论(0编辑  收藏  举报

导航