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
Sample Input
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)