UVA10900SoYouWantToBeA2^n-aire?

//UVA10900SoYouWantToBeA2^n-aire?
#include<cstdio>
#include<cstring>
const int maxn = 20 + 5;
double d[maxn];

int main() {
	int n;
	double t;
	while(scanf("%d%lf", &n, &t) == 2 && n) {
		d[n] = (double)(1 << n);
		for(int i = n - 1; i >= 0; i--) {
			double p0 = (double)(1 << i) / d[i + 1];
			if(p0 < t) p0 = t;//符合題意 
			double p1 = (p0 - t) / (1 - t);//計算不參與下次答題的決策的概率
			d[i] = (1 << i) * p1 + (1 + p0) / 2 * d[i + 1] * (1 - p1);//逆推求期望 
		} 
		printf("%.3lf\n", d[0]); 
	}
}
/*
1 0.5
1 0.3
2 0.6
24 0.25
0 0
*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章