码迷,mamicode.com
首页 > 其他好文 > 详细

[ahu 1248] NBA Finals

时间:2015-06-09 11:34:48      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

NBA Finals
Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
Total Submission: 251   Submission Accepted: 41
 
Description
Consider two teams, Lakers and Celtics, playing a series of NBA Finals until one of the teams wins n games. Assume that the probability of Lakers winning a game is the same for each game and equal to p and the probability of Lakers losing a game is q = 1-p. Hence, there are no ties.Please find the probability of Lakers winning the NBA Finals if the probability of it winning a game is p.

 

Input
1st line: the game number (7<=n<=165) the winner played. 
2nd line: the probability of Lakers winning a game p (0<p<1).

 

Output
1st line: The probability of Lakers winning the NBA Finals.
Round the result to 6 digits after the decimal point and keep trailing zeros.

 

Sample Input

7
0.4

Sample Output

0.22884

4

概率DP

一样的题、swustoj 649

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 210

int main()
{
    int n;
    double p;
    double dp[N][N];
    while(scanf("%d%lf",&n,&p)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        for(int i=0;i<=n;i++) dp[0][i]=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dp[i][j]=dp[i-1][j]*p+dp[i][j-1]*(1-p);
            }
        }
        printf("%.6f\n",dp[n][n]);
    }
    return 0;
}

[ahu 1248] NBA Finals

标签:

原文地址:http://www.cnblogs.com/hate13/p/4562670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!