[Cpp] // 9 degrees OJ 1086 dynamic planning of the "minimum cost" // http://ac.jobdu.com/problem.php? Pid = 1086 # include <stdio. h> # define MAXN 2211686018427387904 # define MAXS 30000 long l1, l2, l3, c1, c2, c3, rout [MAXS]; long spe (int start, int end) // enter the start point and end point, and output the cost between the two sites. {Int temp = rout [end]-rout [start]; if (temp <= l1) return c1; if (temp <= l2) return c2; if (temp <= l3) return c3; return MAXN;} int main () {long temp, I, j, a, B, n, spend [MAXS]; while (~ Scanf ("% lld", & l1, & l2, & l3, & c1, & c2, & c3 )) {for (I = temp = 0; I <MAXS; I ++) rout [I] = spend [I] = MAXN; scanf ("% lld ", & a, & B); scanf ("% lld", & n); rout [1] = 0; for (I = 2; I <= n; I ++) scanf ("% lld", & rout [I]); for (I = a, spend [a] = 0; I <B; I ++) {for (j = I + 1; rout [j]-rout [I] <= l3 & j <MAXS; j ++) // ensure that the distance between the input two stations of the spe function is less than or equal to l3. {Temp = spe (I, j); if (spend [j]> spend [I] + temp) spend [j] = spend [I] + temp ;}} printf ("% lld \ n", spend [B]);} return 0 ;}