Hdu 2059 Tortoise and rabbit race (DP)
It is not clear that the remaining power of electric vehicles cannot be used, and each time it is full.
Question Analysis:
For dynamic planning problems, you can perform DP on the site, plus a total of n + 2 sites at the start and end points. The start point indicates that the site is 0, and dp [n + 1] indicates the optimal time of the tortoise, that is, the shortest time, the dynamic conversion equation is: dp [I] = min (dp [I], dp [j] + t1); t1: the optimal (minimum) time from j to I.
AC code:
/*** @ Xiaoran * DP. The question is unclear and the remaining energy cannot be used * dp [I] = min (dp [I], dp [j] + cost ), cost: time from j --> I */# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define LL long longusing namespace std; const double DOB_MAX = 1000000.0; int path [110]; double dp [110]; int main () {int l, n, c, t, vr, vt1, vt2; while (scanf (% d, & l) = 1) {scanf (% d, & n, & c, & t ); scanf (% d, & vr, & vt1, & vt2); for (int I = 1; I <= n; I ++) {scanf (% d, & path [I]);} path [n + 1] = l; dp [0] = 0; double t1, t2; for (int I = 1; I <= n + 1; I ++) {dp [I] = DOB_MAX; for (int j = 0; j
= Len) t1 = len * 1.0/vt1; // else t1 = c * 1.0/vt1 + (len-c) * 1.0/vt2; // use an electric car to drive c, and the remaining pedal if (j) t1 + = t; // calculate the fuel time. // 2. Do not refuel t2 = len * 1.0/vt2; t1 = min (t1, t2); // minimum cost from I to j dp [I] = min (dp [I], dp [j] + t1 );}} if (dp [n + 1]