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}\)。于是暴力 dp,设 \(f[i]\) 表示以值为 \(i\) 的数结尾的符合要求的序列个数,每次添加后更新其所有子集
#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");
}