思路:定义f(x)为 Ai & x==x  的个数,g(x)为x表示为二进制时1的个数,最后答案为    。为什么会等于这个呢:运用容斥的思想,如果 我们假设 ai&x==x 有f(x)个,那么 这f(x)个 组成集合的子集 & 出来是 >=x那么我们要扣掉>x的 。。。  因为这里我们要求的是 & 之后等于0 一开始1个数为0那么就是 1个数为偶数时加上去,  为奇数时减掉了。

那么就剩下求f(x)    。我们把A[i]和x的二进制 分成  前 (20-k)位和  后 k 位时  X1表示A[i]前20-k位 ,X2表示A[i]后k位, Y1表示x前20-k 位,Y2表示A[i]后k位。

 d[k][x] 表示X1==Y1  &&  (X2&Y2==Y2) 那么 d[k][x]转移就能O(1) 转移  ,如下:

当(x&(1<<(k-1)))==1时 d[k][x]=d[k-1][x],   当(x&(1<<(k-1)))==0时d[k][x]=d[k-1][x]+d[k-1][x+(1<<(k-1)];

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
#define N 1050000
#define LL __int64
#define MOD 1000000007
using namespace std;
int f[][N];
int a[N];
LL qmod(LL a, LL b) {
LL res = ;
while (b) {
if (b & )
res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= ;
}
return res;
}
int cal(int i) {
int flag = ;
int res = (int) qmod(, f[][i]);
while (i) {
if (i & )
flag++;
i >>= ;
}
if (flag & )
return -res;
else
return res;
}
int main() {
int n;
scanf("%d", &n);
int w = ( << );
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
f[][a[i]]++;
}
for (int k = ; k <= ; ++k) {
for (int i = ; i < w; ++i) {
if (i & ( << (k - ))) {
f[k][i] = f[k - ][i];
} else {
if (i + ( << (k - )) < w)
f[k][i] = (f[k - ][i] + f[k - ][i + ( << (k - ))])
% (MOD - );
else
f[k][i] = f[k - ][i];
}
}
}
int ans = ;
for (int i = ; i < w; ++i) {
ans = (ans + cal(i)) % MOD;
}
printf("%d\n", (ans+MOD)%MOD);
return ;
}

Codeforces Round #257 (Div. 1) (Codeforces 449D)的更多相关文章

  1. Codeforces Round #257 (Div. 1) (Codeforces 449B)

    题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...

  2. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  3. Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

    目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...

  4. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  5. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  6. Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  7. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  8. Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

  9. Codeforces Round #257 (Div. 2)

    A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...

随机推荐

  1. mysql 大数据量的处理

    insert 1.过滤一段时间内重复的数据2.数据缓存起来,批量写入 select1.使用分区表2.主主复制,连接不同的mysql3.建立索引4.定时求平均值,写入一个新的表中

  2. VIM跳到指定行

    ngg nG :n n is the line number

  3. vim的配置文件及常用的快捷键

    一些最简单的配置,即在.vimrc中可以写入的配置: 首先,说明一点,在.vimrc文件中,可以用“  把一行的配置注销掉. set nocompatible  “关闭 vi 兼容模式:其中 comp ...

  4. JavaSE复习_1 Java的基本格式和运算符

    △.代表在当前目录.classpath能在任何路径下访问类文件. △单行注释可以嵌套,多行注释不能嵌套 △java中的标识符只能有数字,字母,$和_,其他的符号都是错误的,不合法的.其中数字不能是开头 ...

  5. 开启所有PHP错误!无论在任何时候

    开发的时候,会屏蔽所有错误,但是有时候排查太蛋疼, 下面代码粘贴到控制器头部,开所有错误! 不可阻挡   ini_set('display_errors','1'); restore_error_ha ...

  6. 【linux命令】:查看当前登录用户的信息,本文介绍3种方法

    作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动.有些时候,你甚至需要知道他(她)们正在做什么.本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法. 1. 使用w ...

  7. Android控件之ToggleButton(多状态按钮)

    一.概述 ToggleButton有两种状态:选中状态和没选中状态(类似一个开关),并且需要为不同的状态设置不同的显示文本 二.ToggleButton属性 android:checked = &qu ...

  8. Python 调用自定义包

    创建包 # mkdir -p /python/utils # touch /python/utils/__init__.py # vi /python/utils/Log.pyimport timed ...

  9. python语法笔记(七)

    python标准库 Python有一套很有用的标准库(standard library).标准库会随着Python解释器,一起安装在你的电脑中的.它是Python的一个组成部分.这些标准库是Pytho ...

  10. appium支持中文输入

    Appium 1.3.3以上.java:capabilities增加下面两项:capabilities.setCapability("unicodeKeyboard", " ...