标签:
#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; }
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4722548.html