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[][],p;
int i,j,n;
while(cin>>n>>p)
{
for(i=;i<=n;i++)
{
P[i][]=;
P[][i]=;
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
P[i][j]=P[i-][j]*p+P[i][j-]*(-p);
}
}
cout<<P[n][n]<<endl;//cout<<P[n-3][n-3]<<endl
}
return ;
}

SWUST OJ数据有误,http://acm.swust.edu.cn/problem/649/,AC代码:cout<<P[n-3][n-3]<<endl,由于BUG,只能用C++写,用C提交WA。

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) 说明如下:

P[i-1][j]*p( P[i][j-1]*(1-p) ),这里是乘。表面上看,P[i-1][j]相比于P[i][j]多一个胜场,但不能凭感觉地依靠乘法原理,得到 P[i][j]*p=P[i-1][j] ( P[i][j]=P[i-1][j]/p ),原因是,P[i-1][j]相比于P[i][j]在计算时少考虑了这个胜场,P[i-1][j ]的值是大于 P[i][j]的,所以应用 P[i-1][j] 乘以 p,将这个胜场考虑进去。

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

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

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  2. [ahu 1248] NBA Finals

    NBA Finals Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MBTotal Submission: 251 ...

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

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  4. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

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

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  7. [Swust OJ 1026]--Egg pain's hzf

      题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf ...

  8. [Swust OJ 1139]--Coin-row problem

    题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...

  9. [Swust OJ 385]--自动写诗

    题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535    Descripti ...

随机推荐

  1. body书写总框架

    Body-reason 1:Topic sentence 2-n:解释or/and 举例 段内结构: 主题句+解释 主题句+举例 主题句+解释+举例:逐渐细化 不要每一段格式一致

  2. AQS: 什么是AQS?

    AQS定义了一套多线程访问共享资源的同步器框架. 许多同步类实现都依赖于它,如常用的ReentrantLock/ReentrantReadWriterLock/CountDownLatch这些类里面都 ...

  3. div 命名规范! (野路子出来的好好看看)

    DIV命名规范   DIV命名规范 企业DIV使用频率高的命名方法 网页内容类 --- 注释的写法: /* Footer */ 内容区/* End Footer */ 摘要: summary 箭头:  ...

  4. Python笔记_第一篇_面向过程_第一部分_5.Python数据类型之元组类型(tuple)

    元组!在Python中元组是属于列表的一种延伸,也是一种有序集合,成为一种只读列表,即数据可以被查找,不能被修改,列表的切片操作同样适用于元组. 特点:1. 与列表非常相似. 2. 一旦初始化就不能修 ...

  5. vim下看C++代码

    看C++代码, 缺少合适的编辑器,捣鼓vim. 安装Vundle, 用于插件管理 git clone https://github.com/VundleVim/Vundle.vim.git ~/.vi ...

  6. python tricks 01

    01: 考察range/sort/lambda 对以下数据进行排序 原数据: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] 目标数据: [0, -1, 1, -2, 2 ...

  7. xcode垃圾目录以及Mac隐藏显示文件快捷键

    ~/Library/Developer/Xcode/DerivedData 显示:defaults write com.apple.finder AppleShowAllFiles -bool tru ...

  8. 2018-10-09-Pser

    title date tags layout Pser 2018-10-09 杂谈 post ### 踏雪无痕![踏雪无痕](http://da1sy.github.io/assets/images/ ...

  9. shell_xtrabackup_backup_mysql

    #!/bin/bash# Name: xtra_back_mysql.sh# Desc:该脚本使用xtrabackup工具对mysql数据库进行增量备份,根据自己需求可以自行修改# Usage:./x ...

  10. D. Almost All Divisors

    We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means ...