[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]~~受不了~~
 #include<iostream>
#include<cstring>
using namespace std;
int main()
{
double dp[][], p;
int i, j, n;
while (cin >> n >> p)
{
for (i = ; i <= n; i++){
dp[i][] = ;
dp[][i] = ;
}
for (i = ; i <= n; i++){
for (j = ; j <= n; j++){
dp[i][j] = dp[i - ][j] * p + dp[i][j - ] * ( - p);
}
}
cout << dp[n][n] << endl;
}
return ;
}
上一篇:vbox NAT 设置端口映射(NAT+8080端口转发)


下一篇:Vue组件库 VV-UI 开始接受PR啦,有兴趣小伙伴可以一起参与开源哦。