zoukankan      html  css  js  c++  java
  • POJ3682King Arthur's Birthday Celebration(数学期望||概率DP)

    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?

    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
    ",dp[n],money[n]);
        }return 0;
    }
  • 相关阅读:
    iOS开发技巧系列---使用链式编程和Block来实现UIAlertView
    那些著名或非著名的iOS面试题-前编
    App安全之网络传输安全
    高效使用jquery之一:请使用'On'函数
    手把手教你在.NET中创建Web服务
    CSS3弹性盒模型布局模块介绍
    推荐一款超级漂亮的HTML5 CSS3的图片轮播器
    深入了解jquery中的键盘事件
    Javascript实现返回上一页面并刷新
    jQuery中下拉框select的操作方法详解
  • 原文地址:https://www.cnblogs.com/hua-dong/p/8051914.html
Copyright © 2011-2022 走看看