結果

問題 No.1937 Various Tournament
ユーザー Haa
提出日時 2022-05-13 22:22:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 172,896 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-07-22 02:23:15
合計ジャッジ時間 14,781 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int popc(int x){
    int ret=0;
    REP(i,20){
        ret+=x&1;
        x>>=1;
    }
    return ret;
}

int main(){
    int n; cin >> n;
    VVI s(n,VI(n));
    REP(i,n)REP(j,n) cin >> s[i][j];
    VVI dp(1<<n,VI(n,0));
    REP(i,n) dp[1<<i][i]=1;
    REP(i,1<<n){
        int ipc=popc(i);
        if(ipc==1||popc(ipc)!=1) continue;
        for(int j=i;j>0;j=((j-1)&i)){
            if(popc(j)!=ipc/2) continue;
            REP(x,n)REP(y,n){
                if(s[x][y]){
                    dp[i][x]+=dp[j][x]*dp[i^j][y];
                    dp[i][x]+=dp[i^j][x]*dp[j][y];
                }
            }
        }
    }
    REP(i,n) cout << dp[(1<<n)-1][i] << endl;
    return 0;
}
0