hdu3076--ssworld VS DDD(概率dp第三弹,求概率)
发布时间:2020-12-13 22:44:09 所属栏目:百科 来源:网络整理
导读:ssworld VS DDD Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1487Accepted Submission(s): 304 Problem Description One day,sssworld and DDD play games together,but there are some special
ssworld VS DDDTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
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
Sample Output
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,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("%.6lfn",dp[flag][hp2]); } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 控制浏览/仅选择文件夹,而不是ASP.NET中的文件?
- ruby-on-rails – ROR将params传递给模态
- ruby – rbenv exec bundle exec而不仅仅是bundle exec
- [每日一题] OCP1z0-047 :2013-08-21 正则表达式---REGEXP_I
- Ruby DRbObject和覆盖发送
- cocos2d-x XX_selector函数体中无法访问类的成员变量问题
- JsonCPP在linux下的一个奇怪的问题
- 使用swift编译器裸机?
- ruby-on-rails – 如何为“编辑”路径创建Cucumber步骤定义
- 使用ajax异步校验数据的两种方法