Jzzhu and Numbers

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status
Appoint description: 
System Crawler  (2014-07-20)

Description

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).

Sample Input

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
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; typedef __int64 LL;
const LL mod=;
const int maxn=<<;
int dp[][<<];
int a[<<]; LL pow_mod(LL a,LL b)
{
LL ret=;a%=mod;
while(b)
{
if(b&) ret=ret*a%mod;
a=a*a%mod;
b>>=;
}
return ret;
} int main()
{
int n,i,j;
int ans,t,tt;
scanf("%d",&n);
for(i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
if(a[i]&)
{
dp[][ a[i] ]++;dp[][ a[i]^ ]++;
}
else dp[][ a[i] ]++;
}
for(i=;i<;i++)
for(j=;j<maxn;j++)
{
t=<<(i+);
if(j&t)
{
dp[i+][j]+=dp[i][j];dp[i+][ j-t ]+=dp[i][j];
}
else dp[i+][j]+=dp[i][j];
}
ans=;
for(j=;j<maxn;j++)
{
t=;
for(i=;i<;i++)
if((<<i)&j)
t=-t;
tt=pow_mod(,dp[][j]);
tt--;
ans=((ans+t*tt)%mod+mod)%mod;
}
printf("%d\n",ans);
return ;
}

codeforces 449D DP+容斥的更多相关文章

  1. bzoj 3622 DP + 容斥

    LINK 题意:给出n,k,有a,b两种值,a和b间互相配对,求$a>b$的配对组数-b>a的配对组数恰好等于k的情况有多少种. 思路:粗看会想这是道容斥组合题,但关键在于如何得到每个a[ ...

  2. 【BZOJ 4665】 4665: 小w的喜糖 (DP+容斥)

    4665: 小w的喜糖 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 94  Solved: 53 Description 废话不多说,反正小w要发喜 ...

  3. [Luogu P1450] [HAOI2008]硬币购物 背包DP+容斥

    题面 传送门:https://www.luogu.org/problemnew/show/P1450 Solution 这是一道很有意思的在背包里面做容斥的题目. 首先,我们可以很轻松地想到暴力做背包 ...

  4. Codeforces 611C New Year and Domino DP+容斥

    "#"代表不能放骨牌的地方,"."是可以放 500*500的矩阵,q次询问 开两个dp数组,a,b,a统计横着放的方案数,b表示竖着放,然后询问时O(1)的,容 ...

  5. codeforces 342D Xenia and Dominoes(状压dp+容斥)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Xenia and Dominoes Xenia likes puzzles ...

  6. Codeforces.348D.Turtles(容斥 LGV定理 DP)

    题目链接 \(Description\) 给定\(n*m\)的网格,有些格子不能走.求有多少种从\((1,1)\)走到\((n,m)\)的两条不相交路径. \(n,m\leq 3000\). \(So ...

  7. HDU 5838 (状压DP+容斥)

    Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...

  8. [BZOJ 1042] [HAOI2008] 硬币购物 【DP + 容斥】

    题目链接:BZOJ - 1042 题目分析 首先 Orz Hzwer ,代码题解都是看的他的 blog. 这道题首先使用DP预处理,先求出,在不考虑每种硬币个数的限制的情况下,每个钱数有多少种拼凑方案 ...

  9. CF285E Positions in Permutations(dp+容斥)

    题意,给定n,k,求有多少排列是的 | p[i]-i |=1 的数量为k. Solution 直接dp会有很大的后效性. 所以我们考虑固定k个数字使得它们是合法的,所以我们设dp[i][j][0/1] ...

随机推荐

  1. Mac格式化fat32格式

    好的,格式化硬盘可以使用电脑内置的磁盘工具来格式. 在 LaunchPad 中的 实用工具 或 其它 找到 磁盘工具 打开磁盘工具后,找到你的移动硬盘. (这里以我的希捷移动盘来示例) 非常容易找到, ...

  2. springboot超详细笔记

    一.Spring Boot 入门 1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,m ...

  3. Java第7次作业:造人类(用private封装,用static关键字自己造重载输出方法)什么是面向对象程序设计?什么是类和对象?什么是无参有参构造方法 ?什么是封装?

    什么是面向对象程序设计? 我们称为OOP(Object  Oriented  Programming) 就是非结构化的程序设计 要使用类和对象的方法来进行编程 什么是类,什么是对象 类就是封装了属性和 ...

  4. JavaScript中面向对象的三大特性(一个菜鸟的不正经日常)

    经过几天的学习,把jQuery给啃会了,但是运用的还不算特别熟练,总感觉自己在JavaScript方面的基础十分欠缺,所以继续拾起JavaScript,开始更好的编程之旅~ 今天学的是JavaScri ...

  5. pandas实践——美国人口分析

    1.导入文件,并查看数据样本 abbr = pd.read_csv("./state-abbrevs.csv")areas =pd.read_csv("./state-a ...

  6. 动态设置html的title

    使用vue前端框架做,竟然丢弃了很多javascript和html的东西了..动态设置title的方法: 1.使用vue的自定义指令 <div v-title>{{htmltitle}}& ...

  7. atag信息处理

    machine_desc->boot_params参数保存的是u-boot传入的启动参数的地址,如果没有传入启动参数,使用如下的默认参数: /* * This holds our default ...

  8. LeetCode(172)Factorial Trailing Zeroes

    题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...

  9. 【HIHOCODER 1055】 刷油漆(树上背包)

    描述 小Ho有着一棵灰常好玩的树玩具!这棵树玩具是由N个小球和N-1根木棍拼凑而成,这N个小球都被小Ho标上了不同的数字,并且这些数字都是处于1..N的范围之内,每根木棍都连接着两个不同的小球,并且保 ...

  10. POJ:1094-Sorting It All Out(拓扑排序经典题型)

    Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Description An ascending sorted sequence ...