哎,这题我能说想到增加起始和终结点的嘛,一直在想dp[i]和dp[i-1]的关系,然后c就很难处理...
dp[i] = dp[j]+f(i,j)
可以说很水嘛,要哭了
//dp[i] = dp[j]+t(i,j) t(i,j)为i到j的时间 //增加其实和终结点(技巧) #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <string> #include <stack> #include <queue> #include <algorithm> const int inf = (1<<31)-1; const int MAXN = 102; using namespace std; int a[MAXN]; double dp[MAXN]; bool cmp(double a,double b){ if(a-b>0)return true; else return false; } int main() { int l,n,c,t; int vr,vt1,vt2; while(~scanf("%d",&l)){ scanf("%d%d%d",&n,&c,&t); scanf("%d%d%d",&vr,&vt1,&vt2); for(int i=1;i<=n;i++) scanf("%d",&a[i]); a[0] = 0; a[n+1] = l; double ts; for(int i=1;i<=n+1;i++){ dp[i] = inf; for(int j=i-1;j>=0;j--){ if(c>a[i]-a[j])ts = (a[i]-a[j])*1./vt1; else ts = c*1./vt1+(a[i]-a[j]-c)*1./vt2; if(j!=0)ts += t; dp[i] = min(dp[i],ts+dp[j]); } } if(cmp(dp[n+1],l*1./vr)) cout<<"Good job,rabbit!"<<endl; else cout<<"What a pity rabbit!"<<endl; } return 0; }
时间: 2024-11-05 14:31:27