hdu1145.So you want to be a 2^n-aire?
来源:互联网 发布:仙界网络直播间下载txt 编辑:程序博客网 时间:2024/05/16 11:55
http://acm.hdu.edu.cn/showproblem.php?pid=1145
So you want to be a 2n-aire?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 94 Accepted Submission(s): 72
Problem Description
The player starts with a prize of $1, and is asked a sequence of n questions. For each question, he may
quit and keep his prize.
answer the question. If wrong, he quits with nothing. If correct, the prize is doubled, and he continues with the next question.
After the last question, he quits with his prize. The player wants to maximize his expected prize.
Once each question is asked, the player is able to assess the probability p that he will be able to answer it. For each question, we assume that p is a random variable uniformly distributed over the range t .. 1.
quit and keep his prize.
answer the question. If wrong, he quits with nothing. If correct, the prize is doubled, and he continues with the next question.
After the last question, he quits with his prize. The player wants to maximize his expected prize.
Once each question is asked, the player is able to assess the probability p that he will be able to answer it. For each question, we assume that p is a random variable uniformly distributed over the range t .. 1.
Input
Input is a number of lines, each with two numbers: an integer 1 ≤ n ≤ 30, and a real 0 ≤ t ≤ 1. Input is terminated by a line containing 0 0. This line should not be processed.
Output
For each input n and t, print the player's expected prize, if he plays the best strategy. Output should be rounded to three fractional digits.
Sample Input
1 0.5
1 0.3
2 0.6
24 0.25
0 0
Sample Output
1.500
1.357
2.560
230.138
Source
University of Waterloo Local Contest 2005.09.17
题意:
一开始有1美元,有一个游戏,每回合可以选择领当前金钱退出游戏,或者选择继续游戏,赢了金钱double,否则0美元且游戏终止,赢的概率在[t..1]分布。
大致思路:
其实我自己什么思路都没有。题解是酱紫的——
f[i] 表示n-i轮后到得的最大金钱数。则f[0] = 2n
对于第i轮,要不放弃得2i美元,要不有p的机会有f[i - 1]。
因为p分布在[t-1],所以概率密度是1/(1-t), 然后对max(p*f[i], 2n-i)dp积分。
即f[i] = 1/(1-t)*int^1(max(p*f[i], 2n-i)dp) ( int^1(f(x)dx)是对f(x)一重积分。)
其实这个dp方程是还是挺难理解,好像总是有点问题。
代码:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define MAXN #define eps (1e-8)#define INF 1000000000#define abs(x) ( (x) > 0? (x): -(x) )#define sqr(x) ((x) * (x))#define MAX(a, b) ((a) > (b)? (a): (b))#define MIN(a, b) ((a) < (b)? (a): (b))typedef long long LL;int n;double t;void swap( int &x, int &y ) { int temp = x; x = y; y = temp; }int main(){ while ( scanf( "%d%lf", &n, &t ) != EOF && n ) { double f, g; f = (double)( 1 << n ); for ( int i = 1; i <= n; ++i ) { double p = ( 1 << ( n - i ) ) / f; if ( p < t ) g = ( 1 + t ) / 2 * f; else if ( p > 1 ) g = ( 1 << ( n - i ) ); else g = 1 / ( 1 - t ) * ( ( p - t ) * ( 1 << ( n - i ) ) + ( 1 - sqr(p) ) / 2 * f ); f = g; } printf( "%.3lf\n", f ); } return 0;}
- hdu1145.So you want to be a 2^n-aire?
- uva10900 So you want to be a 2n-aire?
- So you want to be a 2n-aire?
- So you want to be a 2n-aire? UVA
- UVA 10900 So you want to be a 2n-aire?
- uva 10900 - So you want to be a 2n-aire?(期望)
- UVA 10900 - So you want to be a 2n-aire?(概率)
- uva10900 - So you want to be a 2n-aire? 概率 递推
- hdu 1145 So you want to be a 2n-aire?
- UVa 10900 - So you want to be a 2n-aire? 期望
- UVA - 10900So you want to be a 2n-aire?(连续概率)
- HDOJ 1145 So you want to be a 2n-aire? 期望DP
- UVa10900 - So you want to be a 2n-aire? (期望)
- UVA10900 So you want to be a 2n-aire?(概率dp)
- 杭电1145 so you want to be a 2n-aire?
- uva 10090 So you want to be a 2n-aire?
- UVa 10900 So you want to be a 2n-aire?
- So you want to be a CIO
- 第 11 部分: 服务器端的 JSON
- 初识haskell
- 全国DNS地址大全
- JAVA中自动把文件打成Jar包
- 6.24
- hdu1145.So you want to be a 2^n-aire?
- 诺基亚WP7真机首次曝光 代号Searay
- Win32Check函数的使用
- matlab xcorr与cov的区别
- 如何利用Interception简化MVVM中的Model和ViewModel的设计
- 我的android开发之旅 1、关于android
- GCC 编译器原理
- 奇怪的流量差
- Solaris FAQ 1.2 转载