Swust OJ NBA Finals (0649)

Source: Internet
Author: User

NBA Finals (0649)

Time limit (ms): 1000 memory Limit (KB): 65535 submission:404 accepted:128 description  Consider-teams, Lakers and Celtics, playing a series Of nba finals until one of the teams wins N games. Assume that the PROBABILITY&NBSP;OF Lakers winning a game are the same for each game and equal to P and the probabilit Y of Lakers 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. (assuming the Lakers and the Celtics Playing the NBA Finals, until the team won N games, the team won the championship, assuming the Lakers win a game is P, that is, the probability of losing the game is 1-p, each game can not be a draw end, ask the Lakers win this series of the probability (haha, this topic is a lake honey))   Input first Line Input the N-games (7<=n<=165) of the NBA Finals second line input the probability of Lakers WI Nning a game P (0< p < 1) (first line: N represents the number of fields a team wins to win) (second line: P is the probability of the Lakers winning a match)  output the probability of Lakers W Inning the NBA finals (the probability of the Lakers winning the championship)  sample Input 70.4 sample Output0.289792 (actually 0.228844)   hintsource 
#include <iostream>#include<cstring>using namespacestd;intMain () {Doublep[205][205],p; intI,j,n;  while(cin>>n>>p) { for(i=1; i<=n;i++) {p[i][0]=0; p[0][i]=1; }         for(i=1; i<=n;i++)        {             for(j=1; j<=n;j++) {P[i][j]=p[i-1][j]*p+p[i][j-1]*(1-p); }} cout<<P[n][n]<<endl;    }    return 0; }

OJ data Error, AC code: COUT&LT;&LT;P[N-3][N-3]&LT;&LT;ENDL, because of the bug, can only be written in C + +, ahu-0j:http://icpc.ahu.edu.cn/oj/problem.aspx? id=294, but submitted in C + +, WA;

Note: This input n means that the match is 2*n+1 field N wins system, input 7 namely 15 field 7 wins system. You can't do it with a combination number, the data is too big. Use DP to do , p[i][j] means : when a team (Lakers) and I game need to win, to win the championship, B (Celtic) and J game need to win, in order to win the championship , the team a (Lakers) won the championship probability, so the border p[i][0]=0 (1<=i<=n) (Team B has won), P[0][i]=1 (1<=i<=n) (a team has won the championship), The required output is p[n][n] (brought into the above P[i][j] to understand), the state transfer equation p[i][j]=p[i-1][j]*p+p[i][j-1]* (1-p) is described as follows:.

Swust OJ NBA Finals (0649)

Related Article

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.