# uva 10529 Dumb Bones 区间期望dp ★★

### 解法：

1.现在只需放置一张牌，问放置次数的期望是多少。

2.对于区间中最后一张牌需要放k次。那么左倒多少次？右倒多少次？

### 代码：

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)
#define mes(a,x,s)  memset(a,x,(s)*sizeof a[0])
#define mem(a,x)  memset(a,x,sizeof a)
#define ysk(x)  (1<<(x))
typedef long long ll;
typedef pair<int, int> pii;
const int INF =0x3f3f3f3f;
const int maxn=1000    ;
int n;
double PL,PR;
double dp[maxn+5];
const double eps=1e-10;
int dcmp(double x)
{
if(fabs(x)<eps)  return 0;
else return x<0?-1:1;
}
double DP(int x)
{
if(dcmp(dp[x])>=0 )  return dp[x];
if(x==0)  return dp[x]=0;
if(x==1)  return dp[x]=1.0/(1-PL-PR);
dp[x]=INF;
for(int i=1;i<=x;i++)
{
int le=i-1,ri=x-i;
dp[x]=min(dp[x],(1-PR)/(1-PL-PR)*DP(le)+(1-PL)/(1-PL-PR)*DP(ri)+1.0/(1-PL-PR));
}
return dp[x];
}
int main()
{
std::ios::sync_with_stdio(false);
while(cin>>n&&n)
{
cin>>PL>>PR;
for0(i,n+1) dp[i]=-1;
cout<<fixed<<setprecision(2)<<DP(n)<<endl;
}
return 0;
}



### 公式：

E[1]=11PLPR$E[1]=\frac {1}{1-PL-PR}$
=PL1PLPR$左偏次数=\frac {PL}{1-PL-PR}$
=PR1PLPR$右偏次数=\frac {PR}{1-PL-PR}$
E=E[]+E[]+11PLPR+PL1PLPRE[]+PR1PLPRE[]$E=E[左]+E[右]+\frac {1}{1-PL-PR}+\frac {PL}{1-PL-PR}E[左]+\frac {PR}{1-PL-PR}E[右]$
=11PLPR+1PR1PLPRE[]+1PL1PLPRE[]$\frac {1}{1-PL-PR}+\frac {1-PR}{1-PL-PR}E[左]+\frac {1-PL}{1-PL-PR}E[右]$

08-07 1937

10-09 543

10-25 372

12-09 838

10-17 1172

08-06 803

09-22 123

08-12 1437

02-22 713

11-28 364