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 ...
随机推荐
- Php中常见的4种随机密码生成方法详解
使用PHP开发应用程序,尤其是网站程序,常常需要生成随机密码,如用户注册生成随机密码,用户重置密码也需要生成一个随机的密码.随机密码也就是一串固定长度的字符串,这里我收集整理了几种生成随机字符串的方法 ...
- c#byte数组和string类型转换
http://blog.csdn.net/rowanhaoa/article/details/42144313/ 用system.text中的encoding这个类
- Jib构建你的第一个java镜像
jib Official:GoogleContainerTools/jib 本文示例完整demo github地址 github.com/moxingwang/- 想要了解并且使用jib,首先你得知道 ...
- AspNetPager分页控件的使用以及常见错误
原文发布时间为:2009-05-25 -- 来源于本人的百度文章 [由搬家工具导入] 【Repeater采用AspNetPager分页成功↓】 using System;using System.Co ...
- linux2.4内核调度
进程调度需要兼顾3种进程:交互进程,批处理进程,实时进程,在设计一个进程调度机制时需要考虑具体问题 (1)调度时机? 答:进程在用户空间可以pause()或者让内核设置进程为睡眠状态,以此调度,调度还 ...
- python 代码格式
python 代码格式 Python对代码的缩进要求非常严格,如果不采用合理的代码缩进,将抛出SyntaxError异常 Python语句中一般以新行作为为语句的结束符.但是我们可以使用斜杠( )将一 ...
- IIS 配置缓存
IIS8设置应用程序池-高级设置-启动模式:AlwaysRunning 应用程序池-高级设置-进程模型-闲置超时:1740 (分钟) 应用程序-高级设置-常规-预加载已启用:True
- Liunx 重新mount
https://zhidao.baidu.com/question/349907351.html
- weblogic10.3.6忘记用户名或者密码的解决方法
weblogic安装后,忘记访问控制台的用户名或者密码,可通过以下步骤来重置用户名密码. 版本:WebLogic Server 10.3 说明:%DOMAIN_HOME%:指WebLogic Serv ...
- SpringMVC+Shiro权限管理(转载)
源码 http://pan.baidu.com/s/1pJzG4t1 SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shir ...