Jzzhu and Numbers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 modulo1000000007 (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
分析:暴力肯定不行了,考虑容斥;
   答案为ans=Σ(-1)f(x)*pow(2,num[x]),f(x)代表x中二进制1的个数,num[x]代表a[k]&x=x的个数;
   求num[x]=Σcnt[k](a[k]&x=x),即为高维前缀和,与spoj tle类似;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e6+;
const int N=2e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,num[<<];
ll dp[<<],p[maxn];
int main()
{
int i,j;
p[]=;
rep(i,,maxn-)p[i]=p[i-]*%mod;
scanf("%d",&n);
rep(i,,n)scanf("%d",&j),dp[j]++;
rep(i,,)
{
rep(j,,(<<)-)
{
if((~j)&(<<i))(dp[j]+=dp[j^(<<i)])%=mod;
if(j&(<<i))num[j]++;
}
}
ll ret=;
rep(i,,(<<)-)
{
if(num[i]&)ret=(ret-p[dp[i]]+mod)%mod;
else ret=(ret+p[dp[i]])%mod;
}
printf("%lld\n",ret);
return ;
}

最新文章

  1. 翻译:使用 ASP.NET MVC 4, EF, Knockoutjs and Bootstrap 设计和开发站点 - 2
  2. ASP.NET MVC 拓展ViewResult实现word文档下载
  3. 教你写一个web远程控制小工具
  4. 使用a标签删除进行提示
  5. Delphi编译dll时出错&quot;Cannot debug project unless a host application is defined.use the run|parameters...dialog box.&quot;
  6. php获得ip地址
  7. [转载]ODAC (odp.net) 开发到部署
  8. 干掉拖延症!写给新人的GTD方法
  9. IOS 异步GET方法请求
  10. myeclipse如何修改Web项目名称
  11. svn clean up 出错解决方案
  12. MFC对话框中显示背景图片
  13. LeetCode重建二叉树系列问题总结
  14. UVA 679 二叉树
  15. C3P0连接池温习1
  16. zoj4110 Strings in the Pocket(manacher)
  17. VS2017中 C# dll引用(C生成dll,C++生成dll)小结 - 简书
  18. Jquery 组 表单select交互选项
  19. Scala进阶之路-尾递归优化
  20. Windows系统上设置 Git Bash 的 Font 及 Locale

热门文章

  1. Linux VPS上安装KDE, Gnome和VNC
  2. codevs3342绿色通道(单调队列优化dp)
  3. switchhosts+fiddler app抓包
  4. Servlet访问路径的两种方式、Servlet生命周期特点、计算服务启动后的访问次数、Get请求、Post请求
  5. C#图片辅助类,形成缩略图
  6. 在ubuntu系统下下载和卸载skype
  7. Android项目实战_手机安全卫士程序锁
  8. UltraEdit(UE)window破解方法
  9. [Windows Server 2003] ASP.net安装方法
  10. js输出非字符串,非null值