超水的动态规划。最后要对概率求Sigma。
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 61 6 #define MAXK 11 7 8 double dp[MAXK][MAXN]; 9 double a[7]; 10 int b[10] = {5, 12, 22, 29, 33, 38, 42, 46, 50, 55}; 11 12 int main() { 13 int t; 14 int i, j, k, p; 15 16 #ifndef ONLINE_JUDGE 17 freopen("data.in", "r", stdin); 18 #endif 19 20 scanf("%d", &t); 21 for (p=0; p<t; ++p) { 22 for (i=1; i<=6; ++i) 23 scanf("%lf", &a[i]); 24 for (i=0; i<MAXK; ++i) 25 for (j=0; j<MAXN; ++j) 26 dp[i][j] = 0.0; 27 dp[0][0] = 1.0; 28 for (i=1; i<MAXK; ++i) { 29 for (k=0; k<MAXN; ++k) { 30 for (j=1; j<=6; ++j) { 31 if (k+j < MAXN) 32 dp[i][k+j] += dp[i-1][k]*a[j]; 33 else 34 break; 35 } 36 } 37 } 38 if (p) 39 printf("\n"); 40 double sum; 41 for (i=0; i<10; ++i) { 42 sum = 0.0; 43 for (j=1; j<MAXK; ++j) 44 sum += dp[j][b[i]]; 45 printf("%d: %.1lf%%\n", b[i], sum*100); 46 } 47 } 48 49 return 0; 50 }
时间: 2024-12-29 11:59:00