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 }

时间: 2024-12-17 19:44:48

swust oj 649--NBA Finals(dp,后台略(hen)坑)的相关文章

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

[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

背包 [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 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

西电oj 1038 状压dp

西电oj 1038  状压dp 1038: 裁玻璃 时间限制: 1 Sec  内存限制: 128 MB提交: 33  解决: 4[提交][状态][讨论版] 题目描述 张老板的玻璃店开张了,生意火爆.今天,隔壁玻璃店的刘老板拿来一块玻璃,意在刁难张老板.刘老板说:“我这块玻璃是由N(行)*M(列)小正方形玻璃拼成的,但是其中有一些玻璃坏了,我希望你现在把它裁成尽量多的2*2的小玻璃,而且这些小玻璃都不能有坏的地方.如果你裁出来的块数不是最多的,我就把你赶出建材市场.”现在,张老板来拜托你帮他解决这

线段树 [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 组区间[ 

[Swust OJ 402]--皇宫看守(树形dp)

题目链接:http://acm.swust.edu.cn/problem/402/ Time limit(ms): 5000 Memory limit(kb): 65535 Description 太平王世子事件后,陆小凤成了皇上特聘的御前一品侍卫.  皇宫以午门为起点,直到后宫嫔妃们的寝宫,呈一棵树的形状:某些宫殿间可以互相望见.大内保卫森严,三步一岗,五步一哨,每个宫殿都要有人全天候看守,在不同的宫殿安排看守所需的费用不同.  可是陆小凤手上的经费不足,无论如何也没法在每个宫殿都安置留守侍卫