ZOJ - 3640
题意
一个光头掉到了一个洞里,洞里有条路,第条路的难度是,光头一开始有一个能力值,若此时大于等于,光头可以花天走过这条路;不然光头会磨炼天,并且增加能力值。
求光头钻出来的期望值(老葛平了
Analysis
我们用记搜做
表示能力为钻出来的期望天数,如果,加上;如果,加上
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
template<class T>
void read(T &x)
{
T ans=0;short f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}while(ch>='0'&&ch<='9')
{
ans=(ans<<1)+(ans<<3)+(ch^48);
ch=getchar();
}x=ans*f;
}
#define maxn 200010
int n,f;
int c[10001];
double P[maxn];
const double p=1.61803398874989;
double dp(int x){
if(P[x]>-0.5)return P[x];
P[x]=0;
for(int i=1;i<=n;i++)
if(x<=c[i])P[x]+=double(dp(x+c[i])+1.0)/n;
else P[x]+=int(p*c[i]*c[i])/(double)n;
return P[x];
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("testdata.in","r",stdin);
#endif
while(scanf("%d %d",&n,&f)!=EOF){
for(int i=0;i<=200000;i++)P[i]=-1;
for(int i=1;i<=n;i++)read(c[i]);
printf("%.3lf\n",dp(f));
}
}