結果

問題 No.66 輝け☆全国たこやき杯
ユーザー masamasa
提出日時 2015-10-09 17:47:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 72,400 KB
実行使用メモリ 11,784 KB
最終ジャッジ日時 2023-09-27 08:17:05
合計ジャッジ時間 1,287 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,436 KB
testcase_08 AC 4 ms
5,656 KB
testcase_09 AC 14 ms
11,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;


int main() {
	int m, n;

	cin >> m;
	n = pow(2, m);

	vector<int> s(n), s2(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		s2[i] = s[i] * s[i];
	}

	// dp[i][j] = i回戦をjが突破する確率
	vector< vector<double> > prob(m + 1, vector<double>(n, 0));
	prob[0] = vector<double>(n, 1);

	vector< vector <double> > win(n, vector<double>(n, 0.0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) {
				continue;
			}

			win[i][j] = (1.0 * s2[i]) / (s2[i] + s2[j]);
		}
	}

	for (int i = 1; i <= m; i++) {
		int n_person = pow(2, i);
		for (int j  = 0; j < n; j += n_person) {

			int y_begin = j + n_person / 2;
			int y_end   = j + n_person - 1;

			for (int x = j; x < y_begin; x++) {
				for (int y = y_begin; y <= y_end; y++) {
					prob[i][x] += win[x][y] * prob[i - 1][x] * prob[i - 1][y];
					prob[i][y] += win[y][x] * prob[i - 1][x] * prob[i - 1][y];
				}
			}
		}
	}

	printf("%.9f\n", prob[m][0]);
	return 0;
}
0