#include #include #include using namespace std; int main() { int N; cin >> N; vector A(N); for (int i=0;i> A[i]; vector cnt(4); for (int i=0;i(N+1, -1))); DP[N][N][N] = 0; function dfs = [&](int x, int y, int z) { if (DP[x][y][z] != -1) return DP[x][y][z]; DP[x][y][z] = 1.0; // 今回開封 double cnt0 = N - x; // 0 -> 1 if (0 < cnt0) { // dfsが走ると困るので ifを入れる. double p01 = cnt0 / N; DP[x][y][z] += dfs(x+1, y, z) * p01; } // 1 -> 2 if (0 < x - y) { double p12 = 1.0 * (x - y) / N; DP[x][y][z] += dfs(x, y+1, z) * p12; } // 2 -> 3 if (0 < y - z) { double p23 = 1.0 * (y - z) / N; DP[x][y][z] += dfs(x, y, z+1) * p23; } // 3 -> 3 if (0 < z) { double p33 = 1.0 * z / N; DP[x][y][z] /= (1.0 - p33); } return DP[x][y][z]; }; cout << dfs(cnt[1], cnt[2], cnt[3]) << endl; }