結果

問題 No.1151 チャレンジゲーム
ユーザー nikkukun
提出日時 2020-08-07 22:42:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 169,636 KB
実行使用メモリ 10,600 KB
最終ジャッジ日時 2024-09-24 22:56:38
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int BIAS = 200 + 5;
const int M = BIAS * 2 + 5;
const int N = (1 << 10) + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int n;
double f[N][M][2];
int a[N];

// det: now - other
double DFS(int s, int det, int k) {
	if (det < 0 || det > M) return -1.0;
	if (f[s][det][k] != -1.0) return f[s][det][k];
	if (s == 0) {
		f[s][det][k] = (det > BIAS) || (det == BIAS && k);
	} else {
		double maxf = -1.0;
		for (int i = 0; i < n; i++) {
			if ((s >> i) & 1) {
				int ns = s - (1 << i);
				double g0 = DFS(ns, 2 * BIAS - (det + a[i]), k);
				double g1 = DFS(ns, 2 * BIAS - (det + a[i]), k ^ 1);
				if (g0 == -1.0 || g1 == -1.0) continue;
				double p = 1.0 / a[i];
				double nf = (p * (1 - g1) + (1 - p) * (1 + g0 - g1)) / (2 - p);
				maxf = max(maxf, nf);
			}
		}
		f[s][det][k] = maxf;
	}
	return f[s][det][k];
}

int main() {
	ios::sync_with_stdio(0);

	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			f[i][j][0] = f[i][j][1] = -1.0;

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << fixed << setprecision(10) << DFS((1 << n) - 1, BIAS, 0) << endl;

	return 0;
}
0