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
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 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
The probability is the same as the expected method, but you do not need to add 1. DP [I] [J] indicates that a has an I blood volume, and B indicates the probability that a wins when J blood volume exists, because a requires the probability of winning, the probability of winning a In DP [I] [0] A is 1, and that in DP [0] [J] is 0.
A pitfall, the amount of blood is input upside down .... Pitfall for one day...
#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 (probability DP third play, calculate probability)