結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-03-27 01:58:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 936 ms / 2,000 ms |
| コード長 | 1,994 bytes |
| コンパイル時間 | 753 ms |
| コンパイル使用メモリ | 88,780 KB |
| 実行使用メモリ | 20,276 KB |
| 最終ジャッジ日時 | 2024-07-06 21:32:16 |
| 合計ジャッジ時間 | 8,529 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <ctime>
using namespace std;
int bit_count(int s){
int ret = 0;
while(s>0){
ret++;
s -= s&-s;
}
return ret;
}
int main(){
int n;
double pa,pb;
cin >> n >> pa >> pb;
vector<int> a(n),b(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
for(int i=0; i<n; i++){
cin >> b[i];
}
sort(b.begin(), b.end());
auto get_prob = [&](double p){
vector<double> dp_s(1<<n, 0);
vector<bool> used(1<<n, false);
dp_s[(1<<n) - 1] = 1.0;
queue<int> q;
q.push((1<<n) - 1);
while(q.size() > 0){
int s = q.front(); q.pop();
if(used[s]) continue;
used[s] = true;
for(int i=0; i<n; i++){
if((s>>i)&1){
double p_;
if(bit_count(s) == 1) p_ = 1.0;
else if( (1<<i) == (s&-s) ) p_ = p;
else p_ = (1.0-p)/(bit_count(s)-1);
dp_s[ s & ~(1<<i) ] += dp_s[s] * p_;
q.push(s & ~(1<<i));
}
}
}
//dp[k][x] := 残りk枚の時カードxを出す確率
vector<vector<double>> dp(n+1, vector<double>(n, 0));
for(int i=0; i<(1<<n); i++){
int cnt = bit_count(i);
for(int k=0; k<n; k++){
if((i>>k)&1){
double p_;
if(bit_count(i) == 1) p_ = 1.0;
else if( (1<<k) == (i&-i) ) p_ = p;
else p_ = (1.0-p)/(bit_count(i)-1);
dp[cnt][k] += dp_s[i]*p_;
}
}
}
return dp;
};
auto prob_a = get_prob(pa);
/*
for(int i=0; i<n+1; i++){
for(int j=0; j<n; j++){
cerr << prob_a[i][j] << " ";
}
cerr << endl;
}
*/
auto prob_b = get_prob(pb);
/*
for(int i=0; i<n+1; i++){
for(int j=0; j<n; j++){
cerr << prob_b[i][j] << " ";
}
cerr << endl;
}
*/
double e = 0;
for(int k=0; k<=n; k++){
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(a[i] < b[j]) continue;
e += (a[i]+b[j]) * prob_a[k][i] * prob_b[k][j];
}
}
}
printf("%.16f\n", e);
return 0;
}
koyumeishi