[Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

 

题目链接:http://acm.swust.edu.cn/problem/649/

 

Time limit(ms): 1000    Memory limit(kb): 65535
Consider two 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 are no 
ties.Please find the probability of Lakers winning the NBA Finals if the 
probability of it winning a game is p.
Description
first line input the n-games (7<=n<=165)of NBA Finals 
second line input the probability of Lakers winning a game p (0< p < 1)
Input
the probability of Lakers winning the NBA Finals
Output
1
2
7
0.4
Sample Input
1
0.289792
Sample Output
 
题目大意:假设湖人和凯尔特人在打NBA总决赛,直到一支队伍赢下 n 场比赛,那只队伍就获得总冠军,
     假定湖人赢得一场比赛的概率是 p,即输掉比赛的概率为 1-p,每场比赛不可能以平局收场,问湖人赢得这个系列赛的概率
 
解题思路:这就是一个数学题(貌似)高中的概率题,明显一个dp问题,P[i][j]的含义是:当A队还有 i 场比赛需要赢,
         才能夺得冠军,B队还有 j 场比赛需要赢,才能夺得冠军时,A队获得冠军的概率,
     边界 P[i][0]=0 (1<=i<=n)(B队已经夺冠了),P[0][i]=1 (1<=i<=n)(A队已经夺冠了),
     要求的输出即是 P[n][n]。
 
最后友情提示一下:学校OJ(swust oj)太坑,居然输出dp[n-3][n-3]~~受不了~~
 1 #include<iostream>

 2 #include<cstring> 

 3 using namespace std;

 4 int main()

 5 {

 6     double dp[201][201], p;

 7     int i, j, n;

 8     while (cin >> n >> p)

 9     {

10         for (i = 1; i <= n; i++){

11             dp[i][0] = 0;

12             dp[0][i] = 1;

13         }

14         for (i = 1; i <= n; i++){

15             for (j = 1; j <= n; j++){

16                 dp[i][j] = dp[i - 1][j] * p + dp[i][j - 1] * (1 - p);

17             }

18         }

19         cout << dp[n][n] << endl;

20     }

21     return 0;

22 }
View Code

 

你可能感兴趣的:(final)