zoukankan      html  css  js  c++  java
  • 【51nod】1407 与与与与

    【51nod】1407 与与与与

    (f(x))(A_{i} & x == x)(A_{i})的个数

    (g(x))(x)里1的个数

    (sum_{i = 0}^{2^{20}} (-1)^{g(x)}2^{f(x)})

    (f(x))就是按位取反之后的一个FMT卷积,把判断条件改成这一位不存在即可

    也可以用FWT的与卷积直接卷起来

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define ba 47
    #define MAXN 100005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
            if(c == '-') f = -1;
            c = getchar();
        }
        while(c >= '0' && c <= '9') {
            res = res * 10 +c - '0';
            c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
            out(x / 10);
        }
        putchar('0' + x % 10);
    }
    const int MOD = 1000000007;
    int N;
    int a[(1 << 20) + 5],cnt[(1 << 20) + 5],pw[1000005];
    int lowbit(int x) {
        return x & (-x);
    }
    int inc(int a,int b) {
        return a + b >= MOD ? a + b - MOD : a + b;
    }
    int mul(int a,int b) {
        return 1LL * a * b % MOD;
    }
    void update(int &x,int y) {
        x = inc(x,y);
    }
    void Solve() {
        memset(a,0,sizeof(a));
        int d;
        pw[0] = 1;
        for(int i = 1 ; i <= N ; ++i) {
            read(d);a[d]++;
            pw[i] = mul(pw[i - 1],2);
        }
        for(int j = 0 ; j < 20 ; ++j) {
            for(int S = (1 << 20) - 1 ; S >= 0 ; --S) {
                if(!((S >> j) & 1)) {
                    a[S] += a[S ^ (1 << j)];
                }
            }
        }
        int ans = 0;
        for(int S = 0 ; S < (1 << 20) ; ++S) {
            if(S) cnt[S] = cnt[S - lowbit(S)] + 1;
            int t;
            if(cnt[S] & 1) t = MOD - 1;
            else t = 1;
            update(ans,mul(t,pw[a[S]]));
        }
        out(ans);enter;
    }
    int main(){
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        while(scanf("%d",&N) != EOF) Solve();
    }
    
  • 相关阅读:
    JS---元素属性的操作
    JS---异常
    JS---OOP
    T-SQL---分页语句
    mui---在关闭webview之前给出提示
    mui---通过plus.webview.create创建webview并打开新页面并传参到新页面
    mui---要打开的页面loaded不自动显示,等服务器返回数据后,再做处理逻辑
    winform/timer控件/权限设置/三级联动
    winform 进程、线程
    winform 之MDI容器
  • 原文地址:https://www.cnblogs.com/ivorysi/p/11073643.html
Copyright © 2011-2022 走看看