2019 cattle off more school first base linear template field H XOR

H XOR

The meaning of problems

Given a set of numbers, seeking to satisfy all subsets of the exclusive OR is 0, and the length and

analysis

n is 1E5, it is certainly feasible subset enumeration, which we find is usually converted into the contribution of each number, for a set number of XOR and 0. We consider linear group, this group logarithmically linear group, group set length of r, we can know the knowledge of linear algebra, takes a number in the array, the linear base has the only way that the composition of the exclusive oR is 0. So for each group number is not linear, the number may be composed of a subset of his \ (2-NR. 1} ^ {\) , so that the contribution of all numbers constitute a linear group is not \ ((nr) * 2 {nr-1} ^ \) , then for the number of linear Kiri how to do it? , Which translates into a number of the remaining n-1 can not be expressed this number, how many ways represents the numbers, we can count on the rest of the nr again seek a base, how can this shows the number of it, just by a linear Theorem know, the same number of sets of linear groups can be different, but they are the same rank, but this number to be represented in a linear base inside, so that he, the rest of us for a few , or if the rank r, can be expressed, and then the number can be the number n 1-r-subset contribution is composed \ (2-NR. 1} ^ {\) , otherwise, the contribution is 0

#include <cstdio>
#include <cmath>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
typedef  long long  UI;
const int maxn=1e5+9;
int vis[maxn];
UI a[maxn];
const int mod=1e9+7;
ll mul(ll a,ll b){
    return a%mod*b%mod;
}
ll fpow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=mul(ans,a);
        b>>=1;
        a=mul(a,a);
    }
    return ans;
}
#define weishu 62
UI x[weishu+1];
struct LinearBasis{
    UI basis[weishu+1];//32位
    int num;
    int cnt;//极大无关组大小
    void clear(){ memset(basis,0,sizeof(basis)); num=0;cnt=0; }//清零
    void insert(UI x){ basis[num++]=x; }//单纯存数组,没有插入线性基
    bool d_insert(UI x){//直接插入线性基
        bool flag=0;
           for(int j=weishu;j>=0;j--)
            if ((x>>j)&1) {
                if (basis[j]==0) {
                    cnt++;
                    basis[j]=x;
                    return 1;
                }
                else {
                    x^=basis[j];
                }
        }
           return 0;
    }
    void build(){//用数组里面存的数生成线性基
        cnt=0;
        num--;
        for(int i=0;i<=num;i++) x[i]=basis[i];
        memset(basis,0,sizeof(basis));
       for(int i=0;i<=num;i++)  {
           for(int j=weishu;j>=0;j--)
            if ((x[i]>>j)&1) {
                if (basis[j]==0) {
                    cnt++;
                    basis[j]=x[i];
                    break;
                }
                else {
                    x[i]^=basis[j];
                }
            }
        }
        num=0;
    }
    int check(UI x){//判断一个数在不在线性基中
       for(int i=weishu;i>=0;i--)
        if ((x>>i)&1) {
            if (basis[i]==0) break;
            else x^=basis[i];
        }
        return (x==0);
    }
}bs,bs2;
vector<int>v;
int main(){
    int n;
    while(scanf("%d",&n)==1){
        v.clear();
        bs.clear(),bs2.clear();
        for(int i=1;i<=n;i++){
            vis[i]=0;
            scanf("%lld",&a[i]);
        }
        for(int i=1;i<=n;i++){
            if(bs.d_insert(a[i])){
                v.push_back(i);
                vis[i]=1;
            }
        }
        ll r=bs.cnt;
        ll ans=mul(n-bs.cnt,fpow(2,n-bs.cnt-1));
        for(int i=1;i<=n;i++){
            if(vis[i]==0){
                    bs2.d_insert(a[i]);
            }
        }
        for(int i=0;i<v.size();i++){
            bs=bs2;
            for(int j=0;j<v.size();j++){
                if(i!=j){
                    bs.d_insert(a[v[j]]);
                }
            }
            if(bs.cnt==r)ans+=fpow(2,n-1-r);
        }
        ans%=mod;
        printf("%lld\n",ans);
 
 
 
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/ttttttttrx/p/11432117.html