結果
| 問題 | No.1151 チャレンジゲーム |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-10 13:17:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,503 bytes |
| コンパイル時間 | 6,515 ms |
| コンパイル使用メモリ | 196,720 KB |
| 最終ジャッジ日時 | 2025-01-12 19:40:12 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void chmax(double& a, double b){
a = max(a, b);
}
void chmin(double& a, double b){
a = min(a, b);
}
int nth_bit(int64_t num, int n){
return (num >> n) & 1;
}
int main(){
int N;
cin >> N;
vector<double> A(N);
for(int i=0; i<N; i++) cin >> A[i];
int B = 1<<N;
static double dp[1024][1024][2];
for(int s0=0; s0<B; s0++){
int sum0 = 0, sum1 = 0;
for(int i=0; i<N; i++) (nth_bit(s0, i) ? sum0 : sum1) += A[i];
for(int k=0; k<2; k++) dp[s0][B-1-s0][k] = (sum0 > sum1);
}
for(int s0=B-1; s0>=0; s0--) for(int s1=B-1; s1>=0; s1--) if((s0&s1) == 0 && (s0|s1) != B-1){
vector<int> yet;
for(int i=0; i<N; i++) if(nth_bit(s0|s1, i) == 0) yet.push_back(i);
dp[s0][s1][0] = 0;
for(int i : yet){
double tmp = 1;
for(int j : yet){
double res = (A[j]*dp[s0|(1<<i)][s1][1] + (A[i]-1)*dp[s0][s1|(1<<j)][0]) / (A[i]+A[j]-1);
chmin(tmp, res);
}
chmax(dp[s0][s1][0], tmp);
}
dp[s0][s1][1] = 1;
for(int j : yet){
double tmp = 0;
for(int i : yet){
double res = ((A[j]-1)*dp[s0|(1<<i)][s1][1] + A[i]*dp[s0][s1|(1<<j)][0]) / (A[i]+A[j]-1);
chmax(tmp, res);
}
chmin(dp[s0][s1][1], tmp);
}
}
cout << fixed << setprecision(10) << dp[0][0][0] << endl;
return 0;
}