Swust OJ 649--nba Finals (DP, background slightly (hen) pit)

Source: Internet
Author: User

Title Link: http://acm.swust.edu.cn/problem/649/

Time limit (ms): Memory Limit (KB): 65535Consider 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
Ties. Please find the probability of Lakers winning the NBA finals if the
Probability of it winning a game is P.descriptionfirst line input the N-games (7<=n<=165) of the NBA finals
Second line input the probability of Lakers winning a game P (0< p < 1) inputthe probability of Lakers winning the NB A Finalsoutput
12 70.4
Sample Input
1 0.289792
Sample Output title to the main idea: if the Lakers and the Celtics in the NBA Finals, until a team to win 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 end in a draw, ask the Lakers to win this series Game probability problem Solving ideas: This is a math problem (seemingly) high school probability problem, obviously a DP question, p[i][j] meaning is: When a team and I game need to win, to win the championship, B team and J game need to win, in order to win the championship, a team won the probability of the championship, the border P I [0]=0 (1<=i<=n) (Team B has won the Championship), P[0][i]=1 (1<=i<=n) (Team A has won the championship), the required output is p[n][n].finally friendship Hint: school OJ (swust OJ) too pit, incredibly output dp[n-3][n-3]~~ can't stand ~ ~
1#include <iostream>2#include <cstring>3 using namespacestd;4 intMain ()5 {6     Doubledp[201][201], p;7     intI, J, N;8      while(Cin >> N >>p)9     {Ten          for(i =1; I <= N; i++){ Onedp[i][0] =0; Adp[0][i] =1; -         } -          for(i =1; I <= N; i++){ the              for(j =1; J <= N; J + +){ -DP[I][J] = dp[i-1][J] * p + dp[i][j-1] * (1-p); -             } -         } +cout << Dp[n][n] <<Endl; -     } +     return 0; A}
View Code

Swust OJ 649--nba Finals (DP, background slightly (hen) pit)

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.