HDU 3076 ssworld VS DDD 概率DP入门
来源:互联网 发布:编程技术流 编辑:程序博客网 时间:2024/04/29 22:33
题目描述:
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 51.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 1.0005 50.000 0.000 0.000 0.000 0.000 1.0001.000 0.000 0.000 0.000 0.000 0.000
Sample Output
0.0000001.000000
Source
2009 Multi-University Training Contest 17 - Host by NUDT
题目分析:
A与B玩掷骰子游戏。每个人都有一定的血量,再给出每个人掷1~6的概率,输了一次扣一滴血,到0血就输了。求A能够赢得概率。
这题是概率DP的入门,记录下A和B赢得概率并对他们的血量进行DP。
这题我居然MLE了。原来是对double的二维数组进行memset的问题。
代码如下:
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int MAXN =2005;double aa[7],bb[7];int a,b;double pa,pb;//pa表示a一次赢得几率 pb同理double tie;double dp[MAXN][MAXN];//dp[i][j]表示第一个人有i血赢了有j血的第二个人的概率int main(){ while(~scanf("%d%d",&a,&b)) { for(int j=1; j<=6; j++) { scanf("%lf",&aa[j]); } for(int j=1; j<=6; j++) { scanf("%lf",&bb[j]); } pa=pb=0.0; //memset(dp,0,sizeof(dp));这个东西这么占内存空间吗 for(int i=2; i<=6; i++) { for(int j=1; j<i; j++) { pa+=aa[i]*bb[j];//a取i赢的几率 pb+=bb[i]*aa[j];//b取i赢的几率 } } tie=1-pa-pb; pa=pa/(1.0-tie); pb=pb/(1.0-tie); //printf("%lf %lf\n",pa,pb); dp[0][0]=1; for(int i=0; i<a; i++) { for(int j=0; j<=b; j++) { if (i || j) { dp[i][j]=0.0; if (i) dp[i][j]+=dp[i-1][j]*pa;//a赢一次 if (j) dp[i][j]+=dp[i][j-1]*pb;//b赢一次 } } } double ans=0; for(int i=0; i<b; i++) ans+=dp[a-1][i]*pa; printf("%.6lf\n",ans); } return 0;}
- HDU 3076 ssworld VS DDD 概率DP入门
- HDU 3076 ssworld VS DDD 概率DP
- hdu 3076 ssworld VS DDD 概率DP
- 【HDU】3076 ssworld VS DDD 概率DP
- hdu 3076 ssworld VS DDD (概率dp)
- hdu 3076 ssworld VS DDD 概率dp
- HDU 3076 ssworld VS DDD (概率DP)
- hdu 3076 ssworld VS DDD 概率dp
- HDU 3076 ssworld VS DDD 概率DP
- HDU 3076 ssworld VS DDD (概率dp)
- HDU 3076 ssworld VS DDD 【概率dp】
- ssworld VS DDD hdu 概率DP
- HDU 3076 ssworld VS DDD DP 概率水题
- HDU 3076 ssworld VS DDD(概率dp)
- hdu 3076 ssworld VS DDD(概率DP)@
- hdu 3076 ssworld VS DDD (概率与期望DP)
- HDOJ 题目3076 ssworld VS DDD(概率dp)
- HDU3076 ssworld VS DDD概率DP
- 关于ios中的转码问题
- 使用Express搭建HTTPs加密服务器
- 图文详解MyEclipse中新建Maven webapp项目的步骤(很详细)
- 计算机网络(网络层)
- 解决php的imagick库Strict Standards: Imagick::clone method is deprecated and it's use should be avoided
- HDU 3076 ssworld VS DDD 概率DP入门
- 万万没想到,公式还能这样编辑!
- gRPC 的协议分析
- R3;在32位进程中得到64位进程映像路径
- 汽车拐弯--三分法的应用1005
- Android开发实践
- 金字塔(函数调用)
- hdu1171 Big Event in HDU --01背包
- sdwebimage相关