機率計算題
不是很了解
參考部落格: http://www.acmerblog.com/hdu-1145-so-you-want-to-be-a-2n-aire-1485.html
AC代碼:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const double eps=;
int n;
double tmp,mo;
double t,res;
double dfs(int k,int money){
if(k==n){
mo=;
tmp=*money;
if(t>mo) return (+t)/*tmp;
else
return (-mo)/(-t)*(+mo)/*tmp+(mo-t)/(-t)*money;
}
tmp=dfs(k+,money*);
mo=money/tmp;
if(t>mo) return (+t)/*tmp;
return (-mo)/(-t)*(+mo)/*tmp+(mo-t)/(-t)*money;
}
int main()
{
while(scanf("%d%lf",&n,&t)!=EOF){
if(n==&&t-<eps) break;
res=dfs(,);
printf("%.3lf\n",res);
}
return ;
}