# codeforces #331 D. Wilbur and Trees (dp)

PS：当由区间[x,y]递推到区间[x',y]时，说明x倒下不会使x'也倒下。

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 1E9+9;
const int maxn = 2006;
int pos[maxn];
double dp[maxn][maxn][2][2];
bool visit[maxn][maxn][2][2];
int h,n,dl[maxn],dr[maxn];
double P;

double dfs(int l,int r,int f1,int f2)
{
if(visit[l][r][f1][f2])
return dp[l][r][f1][f2];
if(l>r)
return 0;
visit[l][r][f1][f2]=1;
double &ans=dp[l][r][f1][f2];

ans+=0.5*P*(min(pos[l]-pos[l-1]-h*f1,h)+dfs(l+1,r,0,f2));
ans+=0.5*(1-P)*(min(pos[r+1]-pos[r]-h*f2,h)+dfs(l,r-1,f1,0));

int L=dr[l];
int R=dl[r];
if(L<r)
ans+=0.5*(1-P)*(pos[L]-pos[l]+h+dfs(L+1,r,1,f2));
else
ans+=0.5*(1-P)*(pos[r]-pos[l]+min(pos[r+1]-pos[r]-h*f2,h));

if(R>l)
ans+=0.5*P*(pos[r]-pos[R]+h+dfs(l,R-1,f1,1));
else
ans+=0.5*P*(pos[r]-pos[l]+min(pos[l]-pos[l-1]-h*f1,h));

//	printf("%d %d %d %d  %.15lf\n",l,r,f1,f2,ans);
return ans;
}

int main()
{
int i,j,k;
scanf("%d%d%lf",&n,&h,&P);
for(i=1;i<=n;i++)
scanf("%d",&pos[i]);
sort(pos+1,pos+n+1);
pos[0]=-INF;
pos[n+1]=INF;
dr[n]=n;
for(i=n-1;i>=1;i--)
dr[i]=(h>pos[i+1]-pos[i]?dr[i+1]:i);
dl[1]=1;
for(i=2;i<=n;i++)
dl[i]=(h>pos[i]-pos[i-1]?dl[i-1]:i);
printf("%.10lf\n",dfs(1,n,0,0));
return 0;
}


03-01 219

07-31 1273

08-03 563

09-16 1164

02-23 588

03-05 117

08-01 349

05-16 243

01-19 297

11-24 506