思路:定义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. js模块化编程总结

    大家都知道,js中的变量(variable)有其作用范围,比如:函数里用var定义的变量在函数外是看不到的,而定义在函数外面的变量(不能有没有var修饰)均是全局变量,在js程序的任何位置都可以访问. ...

  2. poj3714Raid(平面最近点对)

    链接 模板 稍加一点标记 模板 #include <iostream> #include<cstdio> #include<cstring> #include< ...

  3. Android 设置进度条背景

    Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...

  4. 2 CSS

    2 CSS CSS基础 html 在一个网页中负责的事情是一个页面的结构css(层叠样式表) 在一个网页中主要负责了页面的数据样式. 编写css代码的方式:     第一种: 在style标签中编写c ...

  5. gdufs 1237 最优分解问题

    题目链接:http://cstfs.gdufs.edu.cn:8080/JudgeOnline/problem.jsp?id=1237 (好像是内网的0.0) 简单来说,这道题目就是把一个数分解为若干 ...

  6. GO语言中间的derfer

    defer Go语言中有种不错的设计,即延迟(defer)语句,你可以在函数中添加多个defer语句.当函数执行到最后时,这些defer语句会按照逆序执行, 最后该函数返回.特别是当你在进行一些打开资 ...

  7. spring @ExceptionHandler注解方式实现异常统一处理

    首先,在我们的工程中新建BaseController父类,内容如下: package com.ztesoft.zsmartcity.framework.exception; import java.i ...

  8. Lucene 基础理论 (zhuan)

    http://www.blogjava.net/hoojo/archive/2012/09/06/387140.html**************************************** ...

  9. IIS_各种问题

    IIS7中默认是已经加载了脚本映射处理.但今天装了个WIN7,装好IIS后却发现没有.于是手动去这安装,在添加html映射时提示:模块列表中必须要有IsapiModule或cgiModule 因为 I ...

  10. iOS开发 差间距滚动

    CGFloat fView_Height(UIView *aView) { return aView.frame.size.height; } CGFloat fView_Width(UIView * ...