You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
2.0 KiB
48 lines
2.0 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int INF = 0x3f3f3f3f;
|
|
const int N = 15;
|
|
double f[N][N][N][N][5][5];
|
|
int a, b, c, d;
|
|
int main() {
|
|
memset(f, -1, sizeof f);
|
|
cin >> a >> b >> c >> d;
|
|
|
|
for (int i = 13; i >= 0; i--)
|
|
for (int j = 13; j >= 0; j--)
|
|
for (int k = 13; k >= 0; k--)
|
|
for (int w = 13; w >= 0; w--)
|
|
for (int x = 4; x >= 0; x--)
|
|
for (int y = 4; y >= 0; y--) {
|
|
double &v = f[i][j][k][w][x][y];
|
|
if (i + (x == 1) + (y == 1) >= a && j + (x == 2) + (y == 2) >= b
|
|
&& k + (x == 3) + (y == 3) >= c && w + (x == 4) + (y == 4) >= d) {
|
|
v = 0;
|
|
continue;
|
|
}
|
|
|
|
v = 1;
|
|
int sum = i + j + k + w + (x != 0) + (y != 0);
|
|
if (i < 13) v += f[i + 1][j][k][w][x][y] * (13 - i) / (54 - sum);
|
|
if (j < 13) v += f[i][j + 1][k][w][x][y] * (13 - j) / (54 - sum);
|
|
if (k < 13) v += f[i][j][k + 1][w][x][y] * (13 - k) / (54 - sum);
|
|
if (w < 13) v += f[i][j][k][w + 1][x][y] * (13 - w) / (54 - sum);
|
|
if (x == 0) {
|
|
double t = INF;
|
|
for (int u = 1; u <= 4; u++) t = min(t, f[i][j][k][w][u][y] / (54 - sum));
|
|
v += t;
|
|
}
|
|
if (y == 0) {
|
|
double t = INF;
|
|
for (int u = 1; u <= 4; u++) t = min(t, f[i][j][k][w][x][u] / (54 - sum));
|
|
v += t;
|
|
}
|
|
}
|
|
|
|
if (f[0][0][0][0][0][0] > 54)
|
|
printf("-1.000");
|
|
else
|
|
printf("%.3lf", f[0][0][0][0][0][0]);
|
|
|
|
return 0;
|
|
} |