ssworld VS DDD

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1487    Accepted Submission(s): 304

Problem Description
One day, sssworld and DDD play games together, but there are some special rules in this games.

They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1, P2 <= 6). Small number who, whose HP to reduce 1, the same points will remain unchanged. If one of them becomes 0 HP, he loses. 

As a result of technical differences between the two, each person has different probability of throwing 1, 2, 3, 4, 5, 6. So we couldn’t predict who the final winner. 


 
Input
There are multiple test cases.

For each case, the first line are two integer HP1, HP2 (1 <= HP1, HP2 <= 2000), said the first player sssworld’s HP and the second player DDD’s HP. 

The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end. 
 
Output
One float with six digits after point, indicate the probability sssworld won the game.
 
Sample Input
5 5
1.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 1.000
5 5
0.000 0.000 0.000 0.000 0.000 1.000
1.000 0.000 0.000 0.000 0.000 0.000
 
Sample Output
0.000000
1.000000
 
Source
2009 Multi-University Training Contest 17 - Host by NUDT

求概率。和求期望的方法同样,只是不用再+1,dp[i][j]表示a有i血量,b有j血量时a赢的概率,由于要求a赢的概率。所以在dp[i][0]a赢得概率是1,dp[0][j]时a赢的概率是0。

一个坑点。血量是倒着输入的。

。。。坑了一天。。。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int hp1 , hp2 ;
double dp[2][2100] ;
double a , b , p ;
double ka[10] , kb[10] ;
int main()
{
int i , j , flag ;
while(scanf("%d %d", &hp2, &hp1)!=EOF)
{
for(i = 1 ; i <= 6 ; i++)
scanf("%lf", &ka[i]);
for(j = 1 ; j <= 6 ; j++)
scanf("%lf", &kb[j]);
memset(dp,0,sizeof(dp));
a = b = p = 0.0 ;
for(i = 1 ; i <= 6 ; i++)
for(j = 1 ; j <= 6 ; j++)
{
if(i > j)
a += ka[i]*kb[j] ;
else if( i < j )
b += ka[i]*kb[j] ;
else
p += ka[i]*kb[j] ;
}
dp[0][0] = dp[1][0] = 1.0 ;
flag = 0 ;
for(i = 1 ; i <= hp1 ; i++)
{
flag = 1 - flag ;
for(j = 0 ; j <= hp2 ; j++)
{
if( j == 0 ) continue ;
dp[flag][j] = ( a*dp[flag][j-1] + b*dp[1-flag][j] ) / (1.0-p) ;
}
}
printf("%.6lf\n", dp[flag][hp2]);
}
return 0;
}

hdu3076--ssworld VS DDD(概率dp第三弹,求概率)的更多相关文章

  1. zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)

    One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very ...

  2. HDU3076 ssworld VS DDD

    嘟嘟嘟 友情提示:数据把\(hp1\)和\(hp2\)弄反了! 进入正题. 这题还是比较好想,令\(dp[i][j]\)表示第一个人赢了\(i\)场,第二个人赢了\(j\)的概率,转移就是分别考虑这一 ...

  3. poj2151--Check the difficulty of problems(概率dp第四弹,复杂的计算)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5009   ...

  4. hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. G - 旅行的意义(概率DP) (DAG图的概率与期望)

    为什么有人永远渴望旅行,或许就因为,巧合和温暖会在下一秒蜂拥而至吧. 一直想去旅游的天天决定在即将到来的五一假期中安排一场环游世界的旅行.为此,他已经提前查阅了很多资料,并准备画一张旅游路线图.天天先 ...

  6. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  7. BZOJ3270 博物館 概率DP 高斯消元

    BZOJ3270 博物館 概率DP 高斯消元 @(XSY)[概率DP, 高斯消元] Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博 ...

  8. 概率dp入门

    概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...

  9. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

随机推荐

  1. RS232与TTL

    TTL电平,RS232电平和CMOS电平 不同点:TTL232的0是用0v表示,1是用5V表示.RS232的0是用+3V--+15V表示,1是用-3V---15V表示. 接口一般都用三根线:1:地线: ...

  2. 觉醒力量 (hidpower)

    觉醒力量 (hidpower) 题目描述 [题目背景] 从前有一款非常火的游戏被人们称为pokemon,从最初的红绿蓝黄版直到现在的XY版,都受到世界各地小朋友和大朋友们的喜爱. [题意描述] 作为一 ...

  3. 清理雪道(bzoj 2502)

    Description        滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时 ...

  4. Sql常用日期格式

    原文发布时间为:2010-09-16 -- 来源于本人的百度文章 [由搬家工具导入] SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm ...

  5. 语法错误: 标识符“__RPC__out_xcount_part” 解决方法

    1.错误描述 2.解决方案:将 $(DXSDK_DIR)\Include; 放到最后面,如下

  6. UVALive 6514:Crusher’s Code(概率dp)

    题目链接 https://icpcarchive.ecs.baylor.edu/external/65/6514.pdf 题意:给出n个数(n<8) 求这n个数分别两个程序排成有序时,程序的期望 ...

  7. JWT在PHP使用及问题处理

    官网 https://jwt.io/ 3.0版本 https://github.com/lcobucci/jwt 安装 composer require lcobucci/jwt 依赖 PHP 5.5 ...

  8. 解决redis在windows下使用start命令行调起时闪退的问题

    start powershell "redis-server.exe" "redis-server.exe" 改成redis-server.exe的绝对路径即可 ...

  9. Codeforces 429D Tricky Function(平面最近点对)

    题目链接  Tricky Function $f(i, j) = (i - j)^{2} + (s[i] - s[j])^{2}$ 把$(i, s[i])$塞到平面直角坐标系里,于是转化成了平面最近点 ...

  10. java 之webmagic 网络爬虫

    webmagic简介: WebMagic是一个简单灵活的Java爬虫框架.你可以快速开发出一个高效.易维护的爬虫. http://webmagic.io/ 准备工作: Maven依赖(我这里用的Mav ...