結果

問題 No.133 カードゲーム
ユーザー koyumeishi
提出日時 2015-01-30 17:26:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,462 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-06-25 03:28:58
合計ジャッジ時間 1,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
int bit_count(int x){
int ret = 0;
while(x>0){
ret++;
x -= x & -x;
}
return ret;
}
double dfs(vector<vector<vector<double>>> &dp, const int &n, const int &a, const int &b, int s, int t, int w){
if(w<0) return 0.0;
if(dp[s][t][w] >= 0) return dp[s][t][w];
if(s==a){
if(w==0) return 1.0;
else return 0.0;
}
double ret = 0;
double p = 1.0/(bit_count(s)+1);
for(int i=0; i<2*n; i++){
if( ((1<<i) & a) == 0 ) continue;
if( ((1<<i) & s) > 0 ) continue;
for(int j=0; j<2*n; j++){
if( ((1<<j) & b) == 0 ) continue;
if( ((1<<j) & t) > 0 ) continue;
if(i>j){
ret += dfs(dp, n, a,b,s^(1<<i),t^(1<<j), w-1) * p * p;
}else if(i<j){
ret += dfs(dp, n, a,b,s^(1<<i),t^(1<<j), w) * p * p;
}
}
}
dp[s][t][w] = ret;
return ret;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for(int i=0; i<n; i++){
cin >> a[i];
a[i]--;
}
for(int i=0; i<n; i++){
cin >> b[i];
b[i]--;
}
vector<vector<vector<double>>> dp(1<<(2*n), vector<vector<double>>(1<<(2*n), vector<double>(n+1, -1)));
int s = 0;
int t = 0;
for(int i=0; i<n; i++){
s |= (1<<a[i]);
t |= (1<<b[i]);
}
double ans = 0.0;
for(int i=n/2+1; i<=n; i++){
ans += dfs(dp,n,s,t,0,0, i);
}
printf("%.6f\n", ans);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0