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. Android巩固之事件分发机制

    https://www.cnblogs.com/liaojie970/p/5869152.html onTouchEvent是真正用来进行业务逻辑处理的地方,返回true表示已经将该事件消费,返回fa ...

  2. c语言中多维数组和指针的关系

    如图: 执行结果: 说明:由执行结果可知,三个输出的结果相等(可能在不同的平台执行结果不相同,但三个的结果是相等的),数组multi的地址与数组multi[0]的地址相同,都等于存储的第一个整数的地址 ...

  3. ant design vue 时间选择器只能到最大日期

    <a-date-picker :disabledDate="disabledEndDate"  style="width: 100%" placehold ...

  4. LFW Face Database下载

    http://vis-www.cs.umass.edu/lfw/ Download the database: All images as gzipped tar file (173MB, md5su ...

  5. RL78 RAM GUARD Funtion

    1.段设置 在Section段增加 My_ProtectRAM_n段, 段地址为RAM起始地址+256字节 2.变量定义 #pragma section bss My_ProtectRAM/*My_P ...

  6. 扯下Python的super()

    注: Python 2.7.x 环境下 今晚搜东西无意中看到这篇Understanding Python super() with __init__() methods. 其实这篇老早就看过了, 不过 ...

  7. ASP.NET core MVC动作过滤器执行顺序

    using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Threading.Tasks; namespace dotnet ...

  8. 33)new和delete关键字

    ---------------------------------------------------------------------------------------------------- ...

  9. Java之接口(java8的新特性)

    public class SubClassTest { public static void main(String[] args) { SubClass s = new SubClass(); // ...

  10. 如何找到我的Python site-packages目录的位置?

    来源:广州SEO 我如何找到我的site-packages目录的位置? #1楼 这对我有用: python -m site --user-site #2楼 从“如何安装Django”文档 (尽管这不仅 ...