hdu3076--ssworld VS DDD(概率dp第三弹,求概率)
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
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.
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.
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
0.000000
1.000000
求概率。和求期望的方法同样,只是不用再+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第三弹,求概率)的更多相关文章
- zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)
One Person Game Time Limit: 1 Second Memory Limit: 32768 KB Special Judge There is a very ...
- HDU3076 ssworld VS DDD
嘟嘟嘟 友情提示:数据把\(hp1\)和\(hp2\)弄反了! 进入正题. 这题还是比较好想,令\(dp[i][j]\)表示第一个人赢了\(i\)场,第二个人赢了\(j\)的概率,转移就是分别考虑这一 ...
- poj2151--Check the difficulty of problems(概率dp第四弹,复杂的计算)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5009 ...
- hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- G - 旅行的意义(概率DP) (DAG图的概率与期望)
为什么有人永远渴望旅行,或许就因为,巧合和温暖会在下一秒蜂拥而至吧. 一直想去旅游的天天决定在即将到来的五一假期中安排一场环游世界的旅行.为此,他已经提前查阅了很多资料,并准备画一张旅游路线图.天天先 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
- BZOJ3270 博物館 概率DP 高斯消元
BZOJ3270 博物館 概率DP 高斯消元 @(XSY)[概率DP, 高斯消元] Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博 ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
随机推荐
- 生成比较短的Token字符串
有的时候,我们需要生成一些Token作为标识:如认证后的标识符,资源的提取码等.一个比较常见的算法是生成一个GUID来作为Token,由于GUID的随机性和唯一性特点,作为Token是一个非常可靠的选 ...
- 草摆动shader
Shader "Custom/Grass" { Properties { _MainTex ("Grass Texture", 2D) = "whit ...
- POJ 2723 Get Luffy Out(2-SAT+二分答案)
Get Luffy Out Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8851 Accepted: 3441 Des ...
- a:active在ios上无效解决方法
原因: By default, Safari Mobile does not use the :active state unless there is a touchstart event hand ...
- bzoj 合集 1079 1791 1876 2208 2306
1079 记忆化瞎搞吧,[a][b][c][d][e][l]表示当前有能涂1次的油漆a个,能涂2次的b个….前一个颜色为l,再搞下转移就行了. 1791 基环树上找直径 1876 高精度 2208 看 ...
- python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
运行出现如下错误 uncode编码警告:在unicode等价比较中,把两个参数同时转换为unicode编码失败.中断并认为他们不相等. windows下的字符串str默认编码是ascii,而pytho ...
- mongodb学习(2)--- nodeJS与MongoDB的交互(使用mongodb/node-mongodb-native)
转载:http://www.cnblogs.com/zhongweiv/p/node_mongodb.html 目录 简介 MongoDB安装(windows) MongoDB基本语法和操作入门(mo ...
- 【12】vue-router 之路由重定向
看之前的项目,突然发现一个不算bug的bug,之前也是一直没有想到,现在发现之后越来越觉得有必要改掉, 项目用的是vue做的,自然切换用的就是路由,一级路由包括:首页.记录和个人中心,二级路由是在记录 ...
- PHP-CI框架数据库连接默认是长连接,需要注意应用场景
在CI框架的数据库配置文件中$db['default'] ['pconnect'] = TRUE,永久的数据库连接是指在您的脚本结束运行时不关闭的连接. 当收到一个永久连接的请求时,PHP将检查是否已 ...
- python斐波那契数列复杂度
契数列 概述: 斐波那契数列,又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.……在数学上,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1,F(n ...