SWUST OJ NBA Finals(0649)

NBA Finals(0649)

Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128

Description

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.

(假设湖人和凯尔特人在打NBA总决赛,直到一直队伍赢下 n 场比赛,那只队伍就获得总冠军,假定湖人赢得一场比赛的概率是 p,即输掉比赛的概率为1-p,每场比赛不可能以平局收场,问湖人赢得这个系列赛的概率(哈哈,这个出题人应该是个湖蜜))

Input

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)

(第一行:n 代表一支队伍获得冠军需要赢得的场数)

(第二行:p 代表湖人赢得一场比赛的概率)

Output

the probability of Lakers winning the NBA Finals

(湖人赢得冠军的概率)

Sample Input

7

0.4

Sample Output

0.289792(实际应为0.228844)

Hint

Source

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

//OJ数据有误,AC代码:cout<<P[n-3][n-3]<<endl,由于BUG,只能用C++写,AHU-0J:http://icpc.ahu.edu.cn/OJ/Problem.aspx?id=294,反而用C++提交,WA;

注:这题输入 n 代表该比赛是 2*n+1 场 n 胜制,输入 7 即 15 场 7胜制。不可以用组合数去做,数据太大了。用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](带入上述P[i][j]去理解),关于状态转移方程 P[i][j]=P[i-1][j]*p+P[i][j-1]*(1-p) 说明如下:。

时间: 2024-07-31 10:26:19

SWUST OJ NBA Finals(0649)的相关文章

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

swust oj 1026--Egg pain&#39;s hzf

题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf is crazy about reading math recently,and he is thinking about a boring problem. Now there are n integers Arranged in a line.For each integer,he wants to know

SWUST OJ Euclid&#39;s Game(0099)

Euclid's Game(0099) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1855 Accepted: 589 Description Starts with two unequal positive numbers (M,N and M>N) on the board. Two players move in turn. On each move, a player has to write on the boar

[ahu 1248] NBA Finals

NBA Finals Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MBTotal Submission: 251   Submission Accepted: 41 Description Consider two teams, Lakers and Celtics, playing a series of NBA Finals until one of the teams wins n games. Ass

线段树 [SWUST OJ 764] 校门外的树 Plus Plus

校门外的树 Plus Plus(0764) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 214 Accepted: 15 Description 西南某科技大学的校门外长度为 L 的公路上有一排树,每两棵相邻的树之间的间隔都是 1 米.我们可以把马路看成一个数轴,马路的一端在数轴 1 的位置,另一端在 L 的位置:数轴上的每个整数点,即 1,2,……,L,都种有一棵树. 现在要将这排树的某一段涂成某种颜色,给定 N 组区间[ 

背包 [POJ 2184 SWUST OJ 145] Cow Exhibition

Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9479   Accepted: 3653 Description "Fat and docile, big and dumb, they look so stupid, they aren't much  fun..."  - Cows with Guns by Dana Lyons The cows want to prove to

[Swust OJ 404]--最小代价树(动态规划)

题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Description 以下方法称为最小代价的字母树:给定一正整数序列,例如:4,1,2,3,在不改变数的位置的条件下把它们相加,并且用括号来标记每一次加法所得到的和. 例如:((4+1)+ (2+3))=((5)+(5))=10.除去原数不4,1,2,3之外,其余都为中间结果,如5,5,10,将中间结果相加

swust oj 1126--神奇的矩阵(BFS,预处理,打表)

题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈特13成功解决了填数矩阵问题.不知道他这一周又从哪儿弄来一神奇的矩阵,于是逃课潜心研究了一周,终于发现了其中的奥秘:该矩阵有2行.4列,即8个小方块,每个小方块上有一个数字,即:1 2 3 45 6 7 8对于这个神奇的矩阵,有3种变换方式,具体如下:变换A:上下两行数字互换,如上图可变为:5 6

[Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Description 哈特13最近在学习数论问题,然后他智商太低,并学不懂.这不,他又碰到不会的题了.题意非常简单: 有n个数字,求出这些数字中两两最大公约数的最大值.你一定要帮助他解决这个问题啊. Input 多组输入,约25组,直到文件末尾.每组数据占2行,第一行为数字个数n,2<=n<=100000第二行即为对应