POJ3682King Arthur's Birthday Celebration(数学期望||概率DP)
2017-12-17 13:40
429 查看
King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. The luxurious celebration will start on his birthday and King Arthur decides to let fate tell when to stop it. Every day he will toss a coin which has probability p that it comes up heads and 1-p up tails. The celebration will be on going until the coin has come up heads for K times. Moreover, the king also decides to spend 1 thousand coins on the first day's celebration, 3 thousand coins on the second day's, 5 thousand coins on the third day's ... The cost of next day will always be 2 thousand coins more than the previous one's. Can you tell the minister how many days the celebration is expected to last and how many coins the celebration is expected to cost?
For every case, there is a line with an integer K ( 0 < K ≤ 1000 ) and a real number p (0.1 ≤ p ≤ 1).
Input ends with a single zero.
For each case, print two number -- the expected number of days and the expected number of coins (in thousand), with the fraction rounded to 3 decimal places.
求天数期望和钱期望。
天数:dp[i]=dp[i]*(1-p)+dp[i-1]*p+1,化简:dp[i]=dp[i-1]+1/p;
money:money[i] = p(money[i-1]+ 2 *(dp[i-1]+1)-1) + (1-p)(money[i] + 2 * (dp[i]+1)-1)。化简:money[i]=money[i-1]+2*dp[i-1]-2*dp[i]+(1+2*dp[i])/p;
http://blog.csdn.net/nmfloat/article/details/50650489
Input
The input consists of several test cases.For every case, there is a line with an integer K ( 0 < K ≤ 1000 ) and a real number p (0.1 ≤ p ≤ 1).
Input ends with a single zero.
Output
For each case, print two number -- the expected number of days and the expected number of coins (in thousand), with the fraction rounded to 3 decimal places.
Sample Input
1 1 1 0.5 0
Sample Output
1.000 1.000 2.000 6.000
题意:
有一个富豪,他决定每天撒钱,并且抛硬币,第一天1块钱,第二天3块钱,第三天5块,直到他抛到硬币向上的数量为K。求天数期望和钱期望。
思路:
天数期望dp很好求,公式一推,代码一敲。钱期望money没想出来,我开始想难道是用第x天结束的期望乘第x天的钱,累加,直到x天的期望乘钱小于0.0001。但是参考了下别人的公式,反正自己是没想出来。天数:dp[i]=dp[i]*(1-p)+dp[i-1]*p+1,化简:dp[i]=dp[i-1]+1/p;
money:money[i] = p(money[i-1]+ 2 *(dp[i-1]+1)-1) + (1-p)(money[i] + 2 * (dp[i]+1)-1)。化简:money[i]=money[i-1]+2*dp[i-1]-2*dp[i]+(1+2*dp[i])/p;
问题:
巴斯卡分布?二项分布???给数学跪了http://blog.csdn.net/nmfloat/article/details/50650489
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=1010; double dp[maxn],money[maxn]; int main() { int n;double p; while(~scanf("%d",&n)&&n){ scanf("%lf",&p); for(int i=1;i<=n;i++) { dp[i]=dp[i-1]+1/p; money[i]=money[i-1]+2*dp[i-1]-2*dp[i]+(1+2*dp[i])/p; } printf("%.3lf %.3lf\n",dp ,money ); }return 0; }
相关文章推荐
- 数学期望和概率DP题目泛做(为了对应AD的课件)
- ZOJ3640Help Me Escape(师傅逃亡系列•一)(数学期望||概率DP)
- [2013山东ACM省赛] The number of steps (概率DP,数学期望)
- ZOJ3329-One Person Game(概率DP求数学期望)
- Uva 11427 Expect the Expected 概率dp 求数学期望
- 借助树的概率dp(期望)+数学-好题-hdu-4035-Maze
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
- CF 148D D. Bag of mice (概率DP||数学期望)
- [hdu4089] Activation【概率dp 数学期望】
- HDU 4405 Aeroplane chess(概率dp,数学期望)
- 借助树的概率dp(期望)+数学-好题-hdu-4035-Maze
- 动态规划练习题:概率DP总结,求解数学期望或概率的题目
- SGU495Kids and Prizes(数学期望||概率DP||公式)
- [poj2096] Collecting Bugs【概率dp 数学期望】
- [hdu4035] Maze【概率dp 数学期望】
- 【概率dp】【数学期望】Gym - 101190F - Foreign Postcards
- bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】
- 【整理】简单的数学期望和概率DP
- POJ2096Collecting Bugs(数学期望,概率DP)
- dp 求数学期望 概率 HDU - 5236