[Ahu 1248] NBA Finals

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.