#include #include using namespace std; const int kMAX_M = 11; int M; int S[1 << kMAX_M]; double memo[(1 << kMAX_M) * 2][1 << kMAX_M]; // memo[node][player] int Pow2(int n) { return n * n; } double WinningProbability(int node_id, int player, int depth) { if (memo[node_id][player] >= 0.0) return memo[node_id][player]; if (depth == M) { return memo[node_id][player] = 1.0; } int player_num = 1 << (M - depth), my_lb, my_ub; // (1 << depth) - 1 => 一番左のいとこのid my_lb = (node_id - ((1 << depth) - 1)) * player_num; my_ub = my_lb + player_num; int l_id = 2 * node_id + 1, r_id = 2 * node_id + 2; double res = 0.0; if (player < (my_lb + my_ub) / 2) { // プレイヤーが左の子に存在する場合 for (int enemy = (my_lb + my_ub) / 2; enemy < my_ub; enemy++) { res += (double)Pow2(S[player]) / (double)(Pow2(S[player]) + Pow2(S[enemy])) * WinningProbability(l_id, player, depth + 1) * WinningProbability(r_id, enemy, depth + 1); } } else { // プレイヤーが右の子に存在する場合 for (int enemy = my_lb; enemy < (my_lb + my_ub) / 2; enemy++) { res += (double)Pow2(S[player]) / (double)(Pow2(S[player]) + Pow2(S[enemy])) * WinningProbability(l_id, enemy, depth + 1) * WinningProbability(r_id, player, depth + 1); } } return memo[node_id][player] = res; } void Solve() { for (int i = 0; i < (1 << kMAX_M) * 2; i++) { for (int j = 0; j < (1 << kMAX_M); j++) { memo[i][j] = -1.0; } } cout << fixed << setprecision(10) << WinningProbability(0, 0, 0) << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> M; for (int i = 0; i < (1 << M); i++) { cin >> S[i]; } Solve(); return 0; }