結果

問題 No.66 輝け☆全国たこやき杯
ユーザー ty70ty70
提出日時 2016-10-22 02:44:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 951 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 144,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-15 10:32:30
合計ジャッジ時間 1,834 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int S[1<<10];
double dp[11][1<<10];

double calc_p(int n, int m){
	return (double)S[n]*S[n] / (double)(S[n]*S[n] + S[m]*S[m]);
}

int main()
{
	memset(S, 0, sizeof(S));
	memset(dp, 0., sizeof(dp));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int M; cin >> M;
	rep (i, 1<<M) cin >> S[i];

	rep (i, 1<<M) dp[0][i] = 1.;
	for (int turn = 1; turn <= M; ++turn){
		for (int me = 0; me < 1<<M; ++me){
			int l = (me >> turn) << turn;
			int r = l + (1<<turn);
			if (me >= (l + r) / 2){
				r = (l + r) / 2;
			}else{
				l = (l + r) / 2;
			} // end if
			double p = 0.;
			for (int you = l; you < r; ++you){
				p += dp[turn - 1][you] * calc_p(me, you);
			} // end for
			dp[turn][me] = p * dp[turn - 1][me];
		} // end for
	} // end for

	printf("%.8lf\n", dp[M][0]);

	return 0;
}
0