题意:
中文。
思路:
这题不是自己的思想。
当对第i个点的最优值进行求解的时候一定存在最后一个加油的点j。这里j直接枚举。
另外将0和n+1个加油站定义为起点和终点。
dp需要加强训练。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int inf=0x3f3f3f3f; int tmp[105]; double dp[105]; int lev[105]; int main() { int l,n,c,t,vr,vt1,vt2; while(scanf("%d%d%d%d%d%d%d",&l,&n,&c,&t,&vr,&vt1,&vt2)!=EOF) { for(int i=1;i<=n;i++) { scanf("%d",&tmp[i]); } tmp[0]=0; tmp[n+1]=l; for(int i=1;i<=n+1;i++) { if(tmp[i]<=c) { dp[i]=((double)tmp[i])/vt1; } else { dp[i]=((double)tmp[i]-c)/vt2+((double)c)/vt1; } double tma; for(int j=1;j<i;j++) { if(tmp[i]-tmp[j]>c) { tma=((double)tmp[i]-tmp[j]-c)/vt2+((double)c)/vt1; } else { tma=((double)tmp[i]-tmp[j])/vt1; } dp[i]=min(dp[i],tma+t+dp[j]); } } if(dp[n+1]<((double)l)/vr) { printf("What a pity rabbit! "); } else { printf("Good job,rabbit! "); } } }