zoukankan      html  css  js  c++  java
  • CodeForces

    Discription

    Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k.

    Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and print this number modulo 1000000007 (109 + 7). Operation x & y denotes bitwise AND operation of two numbers.


    Input

    The first line contains a single integer n (1 ≤ n ≤ 106). The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 106).

    Output

    Output a single integer representing the number of required groups modulo 1000000007 (109 + 7).

    Examples
    Input
    3
    2 3 3
    Output
    0
    Input
    4
    0 1 2 3
    Output
    10
    Input
    6
    5 2 0 5 2 1
    Output
    53




    很明显的套路题。
    我们可以用类似FMT的方法让所有a[]的子集的cnt++,然后统计出对于每种集合 i 的f[i],即选出一堆数and的集合包含i的方案数。
    显然f[i] = 2^cnt[i] - 1。

    然后直接容斥就行了2333

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxn=1000005,ha=1e9+7;
    inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
    inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;}
    
    inline int read(){
    	int x=0; char ch=getchar();
    	for(;!isdigit(ch);ch=getchar());
    	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
    	return x;
    }
    
    int ci[maxn],n,f[maxn],ans,b[maxn];
    
    inline void solve(){
    	for(int i=0;i<=20;i++)
    	    for(int j=1;j<=1e6;j++) if(ci[i]&j) f[j^ci[i]]+=f[j];
    	
    	for(int i=0;i<=1e6;i++) ADD(ans,b[i]?add(ci[f[i]],ha-1):add(ha-ci[f[i]],1));
    }
    
    int main(){
    	n=read();
    	
    	ci[0]=1; for(int i=1;i<=1e6;i++) ci[i]=add(ci[i-1],ci[i-1]);
    	b[0]=1; for(int i=1;i<=1e6;i++) b[i]=b[i^(i&-i)]^1;
    	
    	for(int i=1;i<=n;i++) f[read()]++;
    	
    	solve();
    	
    	printf("%d
    ",ans);
    	return 0;
    }
    
     
  • 相关阅读:
    Chrome滚动条透明的问题
    JavaScript版的简单动画
    关于AS3的事件移除释疑
    JavaScript的Hook
    JavaScript正则表达式的零宽断言
    webgame开发中的文件解密
    GMIC2011:熊俊谈从数据看iOS移动应用开发
    世上最伟大的十个公式
    OS X Lion 正式版制作安装盘全新安装方法说明
    市面上VB.NET的书比较少,推荐一本,下载地址在下面!
  • 原文地址:https://www.cnblogs.com/JYYHH/p/9191115.html
Copyright © 2011-2022 走看看