[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
Sample Input
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]~~受不了~~
View Code
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 |
1 | 0.289792 |
题目大意:假设湖人和凯尔特人在打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
相关文章推荐
- Codeforces Round #188 (Div. 2) A. Even Odds 水题
- 【mysql的设计与优化专题(6)】mysql索引攻略
- PHP通过Thrift操作Hbase
- 欢迎使用CSDN-markdown编辑器
- Anagrams
- MySQL 体系架构 Oracle体系架构 PostgreSQL体系架构
- linux下/dev、/sys/devices 和 /sys/dev 之间区别
- 北大ACM1007——DNA Sorting
- Add Two Numbers
- 设计模式--外观模式
- 九章算法面试题73 翻转链表II
- install tabix/bgzip
- 关于IOS下载缓存的文件
- java中的自定义异常(标准)
- 访问日志格式的自定义
- C++多线程与临界资源实例
- 访问日志格式的自定义
- javascript学习笔记-2:jQuery中$("xx")返回值探究
- FaceBook页面加载技术
- Git-3