• [CTSC2017] 吉夫特


    Description

    给定长度为 (n)(a_1,a_2,...,a_n) 的有多少个长度为 (ge 2) 的不升子序列 ({ a_{b_1},a_{b_2},...,a_{b_k} }) 满足 (prod_{i=2}^k inom {a_{b_{i-1}}} {a_{b_i}} mod 2 > 0)

    Solution

    用 Lucas 定理对 (inom {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");
    }
    
  • 相关阅读:
    数据结构与算法基础 模块七
    操作系统
    数据结构与算法基础 模块六
    数据库技术
    数据库技术
    数据库 SQL语句
    数据结构与算法基础 模块五
    同源策略和解决
    初识单例模式
    Django—内置用户权限管理
  • 原文地址:https://www.cnblogs.com/mollnn/p/13693625.html
Copyright © 2020-2023  润新知