結果
問題 |
No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
|
ユーザー |
👑 ![]() |
提出日時 | 2022-11-28 02:32:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 1,000 ms |
コード長 | 1,068 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 201,764 KB |
最終ジャッジ日時 | 2025-02-09 01:46:13 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; bool bit(int S, int k){ return (S>>k)&1; } int main(){ const int N=19; const int U=1<<N; vector<vector<bool>> B(N, vector<bool>(N, false)); for (int i=0; i<N; i++){ int L; cin >> L; for (int j=0; j<L; j++){ int a; cin >> a; B[i][a-1]=true; } } vector<int> popcount(U, 0); for (int S=1; S<(1<<N); S++){ popcount[S]=popcount[S>>1]+(S&1); } vector<ll> DP0(U, 0), DP1(U, 0); for (int S=U-1; S>=0; S--){ if (popcount[S]==N){ DP0[S]=1; continue; } int t=0; for (int j=0; j<N; j++){ if (bit(S,j)) continue; if (B[popcount[S]][j]){ int T=S|(1<<j); if (t&1){ DP0[S]+=DP1[T]; DP1[S]+=DP0[T]; }else{ DP0[S]+=DP0[T]; DP1[S]+=DP1[T]; } } t++; } } cout << DP0[0] << " " << DP1[0]; }