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 ...
随机推荐
- 逆向中静态分析工具——IDA初学者笔记
逆向中静态分析工具——IDA初学者笔记 //****************************************************************************** ...
- hihoCoder #1661 数组区间
题目大意 给出 $1$ 到 $n$ 的一个排列($n\le 10^5$),记做 $a_1, a_2, \dots, a_n$ .(注:原题面表述为:"给定 $n$ 个互不相同且不超过 $n$ ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
- javaScript 笔记(4) -- 弹窗 & 计时事件 & cookie
弹窗 可以在 JavaScript 中创建三种消息框:警告框.确认框.提示框. 警告框:经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语法: window ...
- rpm包安装mysql5.6.*版本
1.查看是否已经安装Mysql rpm -qa | grep -i mysql #删除已经安装的Mysql程序 rpm -ev *****.rpm 2.检查是否还有残留mysql文件夹 find / ...
- [LeetCode] Maximum Product Subarray 连续数列最大积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- SQL存储过程基础
什么是存储过程呢?存储过程就是作为可执行对象存放在数据库中的一个或多个SQL命令. 通俗来讲:存储过程其实就是能完成一定操作的一组SQL语句. 那为什么要用存储过程呢?1.存储过程只在创造时进行编译, ...
- 记录: 百度webuploader 分片文件上传java服务器端(spring mvc)示例的优化
最近项目上用到文件分片上传,于是找到了百度的一个开源前端控件webuploader. 于是尝试使用. 下载下来后,它提供的服务器端示例代码是php版的,那么Java版的呢? 其实,上传文件都是按照rf ...
- Hotspot JVM下,parallel与concurrent的区别
转载于知乎 作者:Ted Mosby链接:https://www.zhihu.com/question/21535747/answer/144884632来源:知乎著作权归作者所有.商业转载请联系作者 ...
- 牛客网 牛客练习赛13 C.幸运数字Ⅲ-思维
C.幸运数字Ⅲ 链接:https://www.nowcoder.com/acm/contest/70/C来源:牛客网 这个题447和477是特殊的,其他的就没什么了. 代码: 1 #i ...