[CTSC2017] 吉夫特 - Lucas定理,狀態壓縮dp
阿新 • • 發佈:2020-09-18
Description
給定長度為 \(n\) 個 \(a_1,a_2,...,a_n\) 的有多少個長度為 \(\ge 2\) 的不升子序列 \(\{ a_{b_1},a_{b_2},...,a_{b_k} \}\) 滿足 \(\prod_{i=2}^k \binom {a_{b_{i-1}}} {a_{b_i}} \mod 2 > 0\)。
Solution
用 Lucas 定理對 \(\binom {a_{b_{i-1}}} {a_{b_i}} \mod 2\) 展開,得知要使合法,必須滿足對於任意的 \(i<j\) 有 \(a_{b_i} \subseteq a_{b_j}\)
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1000005; const int mod = 1e9+7; const int dbg = 1; int n,x,f[N],ans,tmp; signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) { cin>>x; int s=x,tmp=f[x]+1; ans+=tmp-1; ans%=mod; // 列舉子集 while(s) { f[s]+=tmp; f[s]%=mod; s=s-1&x; } } cout<<ans<<endl; if(dbg) system("pause"); }