题目地址:http://ac.jobdu.com/problem.php?pid=1086
1 2 3 1 2 3 1 2 2 2
2
#include <stdio.h> #define MAXC 2211686018427387904 #define MAXN 30000 long long l1, l2, l3, c1, c2, c3; //距离、花费 int N; //车站数 long long Compute_Cost(int start, int end, long long len[]); long long getSpend(int start, int end, long long len[]); int main(void){ int start, end; //开始站、结束站 long long len[MAXN] = {0}; int i; while (~scanf("%lld %lld %lld %lld %lld %lld",&l1,&l2,&l3,&c1,&c2,&c3)){ scanf("%d %d", &start, &end); scanf("%d", &N); len[1] = 0; for (i=2; i<=N; ++i){ scanf("%lld", &len[i]); } printf("%lld\n", Compute_Cost(start, end, len)); } return 0; } long long getSpend(int start, int end, long long len[]){ if (len[end] - len[start] <= l1) return c1; else if (len[end] - len[start] <= l2) return c2; else return c3; } long long Compute_Cost(int start, int end, long long len[]){ int i, j; long long min, tmp; long long cost[MAXN] = {0}; cost[start] = 0; for (i=start+1; i<=end; ++i){ min = MAXC; for (j=i-1; j>=start && (len[i]-len[j] <= l3); --j){ tmp = cost[j] + getSpend(j, i, len); if (tmp < min) min = tmp; } cost[i] = min; } min = cost[end]; return min; }