結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
tsutaj
|
| 提出日時 | 2018-02-07 18:36:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 293 ms / 2,000 ms |
| コード長 | 1,578 bytes |
| コンパイル時間 | 414 ms |
| コンパイル使用メモリ | 45,996 KB |
| 実行使用メモリ | 11,364 KB |
| 最終ジャッジ日時 | 2024-07-06 21:43:12 |
| 合計ジャッジ時間 | 3,179 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1 << 28;
int N; double p[2];
int cards[2][20];
double rec[2][20][20];
double dp[1 << 20];
void solve(int t) {
fill(dp, dp + (1 << N), 0);
dp[(1 << N) - 1] = 1.0;
for(int bit=(1<<N)-1; bit>=0; bit--) {
bool fst = true;
for(int i=0; i<N; i++) {
if(bit >> i & 1) {
int nbit = bit ^ (1 << i), cnt = __builtin_popcount(bit);
int step = N - cnt;
if(cnt == 1) {
rec[t][i][step] += dp[bit];
dp[nbit] += dp[bit];
fst = false;
}
else {
double prob = (fst ? p[t] : (1 - p[t]) / (cnt - 1));
rec[t][i][step] += dp[bit] * prob;
dp[nbit] += dp[bit] * prob;
fst = false;
}
}
}
}
}
int main() {
scanf("%d%lf%lf", &N, &p[0], &p[1]);
for(int i=0; i<N; i++) {
scanf("%d", &cards[0][i]);
}
for(int i=0; i<N; i++) {
scanf("%d", &cards[1][i]);
}
sort(cards[0], cards[0] + N);
sort(cards[1], cards[1] + N);
solve(0); solve(1);
double ans = 0.0;
for(int step=0; step<N; step++) {
for(int x=0; x<N; x++) {
for(int y=0; y<N; y++) {
if(cards[0][x] < cards[1][y]) continue;
ans += (cards[0][x] + cards[1][y]) * rec[0][x][step] * rec[1][y][step];
}
}
}
printf("%.12f\n", ans);
return 0;
}
tsutaj