Codeforces Round #257 (Div. 1) (Codeforces 449D)
思路:定义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)的更多相关文章
- Codeforces Round #257 (Div. 1) (Codeforces 449B)
题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...
- 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 ...
- Codeforces Round #524 (Div. 2) codeforces 1080A~1080F
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- 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 ...
- Codeforces Round #257 (Div. 2)
A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...
随机推荐
- 2014 Multi-University Training Contest 1
A hdu4861 打表找规律 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- 关于js的兼容问题(小办法)!
今天整理了一下浏览器对JS的兼容问题,希望能给你们带来帮助,我没想到的地方请留言给我,我再加上: 常遇到的关于浏览器的宽高问题: //以下均可console.log()实验 var winW=docu ...
- ps aux和ps ef的区别
ps aux 是以BSD方式显示ps -ef 是以System V方式显示,该种方式比BSD方式显示的多一重要项--(具体哪项忘了 -_- ) ps aux的输出: USER PID %CPU %ME ...
- Hostapd
Hostapd 一.基本概念 hostapd is an application used to setup your wireless interface as an access-point (m ...
- Java开发中的一些小技巧
原文:http://www.cnblogs.com/xdp-gacl/p/3490276.html 一. Java获取URL地址中传递的参数 /** * 获取URL中的参数名和参数值的Map集合 * ...
- iOS 细碎知识整理
1centerX,即x轴的中点 centery,即y轴的中点
- js代码如何测试代码运行时间
function add(){ //这里放要执行的代码 } //开始测试并输出 function test() { var start=new Date().getTime(); add(); var ...
- java 字符串 转码
//xmlStr 为需要转码的字符串 UTF-8 可改为不同的编码格式 如:GBK //亲测可用 仅供参考 String xmlStrs=""; try{ xmlStrs=new ...
- 谈谈HttpUrlConnection与DefaultHttpClient一些区别
HttpClient封装的很庞大,很复杂,你必须按照,他封装的思想去使用它,导致它很不灵活. 相比之下,HttpUrlConnection很轻巧,很方便,很灵活. HttpClient对于数据上面的封 ...
- TWaver HTML5 (2D)--基本概念
基本概念 TWaver HTML5(以下简称TWaver)使用HTML5技术和javascript语言,可在支持HTML5的浏览器上进行绘图. 使用TWaver前,需熟悉几个基本概念:图元(Eleme ...