[1407] 51nod Yuyuyuyu

[1407] 51nod Yuyuyuyu

Set \ (f (x) \) of \ (A_ {i} \ & x == x \) a \ (A_ {i} \) number

Set \ (g (x) \) of \ (X \) in a number of

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

\ (f (x) \) is by a convolution after FMT bit negated, to determine the conditions into which one can not exist

FWT can also be used with direct convolution volume up

#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('\n')
#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();
}

Guess you like

Origin www.cnblogs.com/ivorysi/p/11073643.html
Recommended