dp[i]表示到i点为止需要的最短时间,枚举上一个状态dp[j],dp[j]是冲好电的情况。
然后就是根据数学方法计算j-i的时间t,那么dp[i]= min { dp[j] + t }
#include<iostream> #include<math.h> #include<stdio.h> #include<algorithm> #include<string.h> #include<string> #include<vector> #include<queue> #include<map> #include<set> #include<stack> #define B(x) (1<<(x)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned ui; const int oo = 0x3f3f3f3f; const ll OO = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; #define lson rt<<1 #define rson rt<<1|1 void cmax(int& a, int b){ if (b > a)a = b; } void cmin(int& a, int b){ if (b < a)a = b; } void cmax(ll& a, ll b){ if (b > a)a = b; } void cmin(ll& a, ll b){ if (b < a)a = b; } void cmax(double& a, double b){ if (a - b < eps) a = b; } void cmin(double& a, double b){ if (b - a < eps) a = b; } void add(int& a, int b, int mod){ a = (a + b) % mod; } void add(ll& a, ll b, ll mod){ a = (a + b) % mod; } const ll MOD = 1000000007; const int maxn = 110; double dp[maxn]; double dis[maxn]; int main(){ //freopen("E:\\read.txt", "r", stdin); int N; double C, T, VR, VT1, VT2, L; while (scanf("%lf", &L) != EOF){ scanf("%d %lf %lf", &N, &C, &T); scanf("%lf %lf %lf", &VR, &VT1, &VT2); for (int i = 1; i <= N; i++) scanf("%lf", &dis[i]); dis[0] = 0.0; dis[++N] = L; fill(dp, dp + N + 2, (double)oo); dp[0] = 0; for (int i = 1; i <= N; i++){ for (int j = 0; j < i; j++){ double t = 0.0; if (j != 0) t += T; if (dis[i] - dis[j] - C < eps) t += (dis[i] - dis[j]) / VT1; else t += C / VT1 + (dis[i] - dis[j] - C) / VT2; cmin(dp[i], dp[j] + t); } } if (dp[N] - L / VR < eps) printf("What a pity rabbit!\n"); else printf("Good job,rabbit!\n"); } return 0; }