結果

問題 No.1151 チャレンジゲーム
ユーザー uzzy
提出日時 2020-08-08 00:44:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,616 bytes
コンパイル時間 2,621 ms
コンパイル使用メモリ 186,900 KB
実行使用メモリ 10,448 KB
最終ジャッジ日時 2024-09-25 02:46:18
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int A[10];
double dp[1024][410][2];
double keisan(int i, int s, int t) {
	if (dp[i][s][t] >= 0) return dp[i][s][t];
	if (i == 0) {
		if (s > 200) dp[i][s][t] = 1;
		else dp[i][s][t] = 0;
		return dp[i][s][t];
	}

	if (t) {
		double ret = 1;
		rep(x, N) if (i >> x & 1) {
			double tmp = keisan(i - (1 << x), s - A[x], 0) / A[x] + keisan(i, s, 0) * (1 - 1.0 / A[x]);
			chmin(ret, tmp);
		}
		return dp[i][s][t] = ret;
	}

	double ret = 0;
	rep(x, N) if (i >> x & 1) {
		double ret2 = 1;
		rep(y, N) if (i >> y & 1) {
			double p1 = 1.0 / A[x];
			double p2 = 1.0 / A[y];

			double tmp1 = p1 / (p1 + (1 - p1) * p2) * keisan(i - (1 << x), s + A[x], 1);
			double tmp2 = (1 - p1) * p2 / (p1 + (1 - p1) * p2) * keisan(i - (1 << y), s - A[y], 0);
			chmin(ret2, tmp1 + tmp2);
		}
		chmax(ret, ret2);
	}
	return dp[i][s][t] = ret;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	rep(i, N) cin >> A[i];
	rep(i, 1 << N) rep(j, 401) rep(k, 2) dp[i][j][k] = -1;
	
	double kotae = keisan((1 << N) - 1, 200, 0);
	cout << setprecision(12) << kotae << endl;

	Would you please return 0;
}
0