NBA FinalsTime limit:1000 MS Case time limit:1000 Ms Memory limit:64 MB
Total submission:251 submission accepted:41 Descriptionconsider, 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 are the same for each game and equal to p and the probability of Laker S losing a game is q = 1-p. Hence, there is no ties. Please find the probability of Lakers winning the NBA finals if the probability of it winning a game is p.
input1st line:the Game Number (7<=n<=165) the winner played.
2nd line:the probability of Lakers winning a game P (0<p<1).
output1st 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
Probability DP
The same question, Swustoj 649
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;#defineN 210intMain () {intN; Doublep; DoubleDp[n][n]; while(SCANF ("%D%LF", &n,&p)! =EOF) {memset (DP,0,sizeof(DP)); for(intI=0; i<=n;i++) dp[0][i]=1; for(intI=1; i<=n;i++){ for(intj=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