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");
}

相关文章:

  • 2021-07-21
  • 2021-07-09
  • 2021-08-30
  • 2022-01-21
  • 2021-12-27
  • 2021-09-16
  • 2021-09-11
  • 2021-11-05
猜你喜欢
  • 2021-09-25
  • 2021-05-25
  • 2021-05-17
  • 2021-08-06
  • 2022-01-25
  • 2022-03-07
相关资源
相似解决方案