您的位置:首页 > 其它

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

2015-06-14 10:30 411 查看
题目链接: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



最后友情提示一下:学校OJ(swust oj)太坑,居然输出dp[n-3][n-3]~~受不了~~

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
double dp[201][201], p;
int i, j, n;
while (cin >> n >> p)
{
for (i = 1; i <= n; i++){
dp[i][0] = 0;
dp[0][i] = 1;
}
for (i = 1; i <= n; i++){
for (j = 1; j <= n; j++){
dp[i][j] = dp[i - 1][j] * p + dp[i][j - 1] * (1 - p);
}
}
cout << dp

<< endl;
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: