HDU 1145So you want...(概率题目 dfs+思维)
来源:互联网 发布:淘宝上ke t 编辑:程序博客网 时间:2024/06/06 18:51
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): 201 Accepted Submission(s): 146
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.51 0.32 0.624 0.250 0
Sample Output
1.5001.3572.560230.138
题目大意:像百万富翁的闯关游戏原理一样。但是百万富翁里面好像如果你不答的话就必须拿上当前现金走人,而这个题可以不走,keep the prize。每次你可以选择不答。也可以选择答题,答对,现金翻倍,错误则没钱。答对每个题目的概率的范围是p~1.给你n,p让你求每次都是最好的选择,然后可以得到的现金期望。
解题思路:开始看了题目,不知所云。懂了意思之后也不知道如何下手。看了下题解,表示题解看了半天才懂。主要用到一个原理,每次把下次可以得到的最大现金期望算出来,然后算下百分比。看下自己是选择不答还是选择答题。
题目地址:So you want to be a 2n-aire?
AC代码:
#include<cstdio>#include<iostream>using namespace std;double t,res;double tmp,mo;int n;double dfs(int k,int money){ if(k==n) { mo=0.5,tmp=2*money; if(t>mo) return (1+t)/2*tmp; return (1-mo)/(1-t)*(1+mo)/2*tmp+(mo-t)/(1-t)*money; } tmp=dfs(k+1,money*2); mo=money/tmp; //是为了找出平衡点 if(t>mo) return (1+t)/2*tmp; return (1-mo)/(1-t)*(1+mo)/2*tmp+(mo-t)/(1-t)*money;}int main(){ while((scanf("%d%lf",&n,&t))!=EOF) { if(n==0&&t==0) break; res=dfs(1,1); printf("%.3lf\n",res); } return 0;}
- HDU 1145So you want...(概率题目 dfs+思维)
- hdu 1145 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? 概率 递推
- UVA - 10900So you want to be a 2n-aire?(连续概率)
- UVA10900 So you want to be a 2n-aire?(概率dp)
- So you want to be a CIO
- So you want to study IR?
- So, You Want A FullScreen Browser, Huh?
- HDOJ 1145 So you want to be a 2n-aire? 期望DP
- 杭电1145 so you want to be a 2n-aire?
- HDU-5978-思维+概率
- So You Want To Enter The Game Industry?
- So you want to be a Game Developer?
- So you want to replay an IIS web server log?
- hdu1145.So you want to be a 2^n-aire?
- So You Want to Be an Embedded Linux Developer
- uva10900 So you want to be a 2n-aire?
- 6.0RMB MP3所看到的……
- android -上传文件到服务器
- 南阳理工ACM 153 king VS king
- 百度地图api的引用中应该注意的问题
- public:接口访问权限
- HDU 1145So you want...(概率题目 dfs+思维)
- Android内存泄漏的各种原因详解
- Android应用开发学习笔记之播放视频
- 获取windows运行状态信息
- 缺省包(default package)
- 史上最受欢迎的十大开源软件
- 网站的favicon详解
- bitmap 在排序中的应用
- avro-rpc