UVa 10900 So you want to be a 2n-aire?
来源:互联网 发布:郑钧 私奔知乎 编辑:程序博客网 时间:2024/05/22 06:09
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. Ifwrong, he quits with nothing.If correct, the prize is doubled,and he continues withthe next question.After the last question, he quitswith his prize. The player wants tomaximize his expected prize.Once each question is asked, theplayer is able to assess the probabilityp that he will be able to answerit. 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. Inputis 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 shouldbe 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
概率+神奇的思路~
设d[i]为第i步的时候的期望钱数。
因为d[i]会受到i之后的d的影响,所以要倒推;而每次答对的概率只有一个范围,所以要先判断范围内哪些概率要答题,那些不需要答题,然后计算就可以了。
哪里用double哪里用int一定要分清!!!
(CSDN又不能给自己点赞了,差评。)
#include<cstdio>#include<iostream>using namespace std;int n,num[31];double p,d[31];int main(){num[0]=1;for(int i=1;i<=30;i++) num[i]=num[i-1]*2;while(scanf("%d%lf",&n,&p)!=EOF && n){d[n]=num[n];for(int i=n-1;i>=0;i--){double p0=max(p,num[i]/d[i+1]),p1=(p0-p)/(1-p);d[i]=p1*num[i];d[i]+=d[i+1]*(1+p0)/2*(1-p1);}printf("%.3lf\n",d[0]);}return 0;}
- 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?(概率)
- UVa 10900 - So you want to be a 2n-aire? 期望
- UVA - 10900So you want to be a 2n-aire?(连续概率)
- UVa 10900 So you want to be a 2n-aire?
- 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?
- uva 10090 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?
- 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?
- So you want to be a CIO
- HFSC Scheduling with Linux
- 声卡 PCM数据格式
- neutron firewall as a sevice
- Android JNI编程(四)——C语言多级指针、数组取值、从控制台输入数组
- JSP页面用EL表达式取值取到/u123形式的中文乱码
- UVa 10900 So you want to be a 2n-aire?
- 遍历Map的四大方法记录
- 图像编码(二)
- WIN10 + VS2015 + WDK10 + SDK10 + VM虚拟机驱动开发调试环境搭建
- 一些面试用到的编程
- android studio 无法关联源代码
- 打jar包时将log4j配置文件放在jar包外的方法
- 如何看Extjs API手册
- Pearls poj1260 (DP)