結果

問題 No.1937 Various Tournament
ユーザー RubikunRubikun
提出日時 2022-05-13 22:06:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,606 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 193,368 KB
最終ジャッジ日時 2025-01-29 07:02:13
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=1LL<<60;

int S[16][16];

ll dp[1<<16][16];
bool seen[1<<16][16];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    //vector<vector<int>> S(N,vector<int>(N));
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>S[i][j];
        }
    }
    
    for(int i=0;i<N;i++) dp[(1<<i)][i]=1;
    for(int bit=0;bit<(1<<N);bit++){
        int x=__builtin_popcount(bit);
        if(!(x==2||x==4||x==8||x==16)) continue;
        for(int T=bit;;T=(T-1)&bit){
            int y=__builtin_popcount(T);
            if(y+y!=x){
                if(T==0) break;
                else continue;
            }
            int U=bit-T;
            for(int i=0;i<N;i++){
                if(!(T&(1<<i))) continue;
                for(int j=0;j<N;j++){
                    if(!(U&(1<<j))) continue;
                    if(S[i][j]) dp[bit][i]+=dp[T][i]*dp[U][j];
                    else dp[bit][j]+=dp[T][i]*dp[U][j];
                }
            }
            
            if(T==0) break;
        }
    }
    
    for(int i=0;i<N;i++) cout<<dp[(1<<N)-1][i]<<"\n";
}

0