首页 > 技术文章 > [ahu 1248] NBA Finals

hate13 2015-06-09 10:03 原文

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;
}

推荐阅读