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 ...
随机推荐
- Oracle存储过程中异步调用的实际操作步骤
本文标签:Oracle存储过程 我们都知道在Oracle数据库的实际应用的过程中,我们经常把相关的业务处理逻辑,放在Oracle存储过程中,客户端以通过ADO来进行相关的调用 .而有些相关的业务逻辑 ...
- 【Todo】【读书笔记】大数据Spark企业级实战版 & Scala学习
下了这本<大数据Spark企业级实战版>, 另外还有一本<Spark大数据处理:技术.应用与性能优化(全)> 先看前一篇. 根据书里的前言里面,对于阅读顺序的建议.先看最后的S ...
- nosql简述
1.NoSQL数据库概念 NoSQL数据库是非关系型数据库,主要是针对关系型数据库而言,它主要是用来解决半结构化数据和非机构化数据的存储问题. 2.为什么使用NoSQL数据库? (1)对数据库的高并发 ...
- ionic 原生日历控件不支持,改用 datepicker-for-ionic
具体参考地址 http://npm.taobao.org/package/datepicker-for-ionic
- POJ水题 1298
#include "stdafx.h" #include <iostream> #include <string> using namespace std; ...
- canvas实现钟表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 最最最简单的轮播图(JQuery)
html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- python 练习 19
#!/usr/bin/python # -*- coding: UTF-8 -*- for n in range(100,1000): i = n / 100 j = n / 10 % 10 k = ...
- [svn] 分支开发
参考博客: http://www.cnblogs.com/cxd4321/archive/2012/07/12/2588110.html (1)为什么要使用SVN分支开发和主干合并? 目的:在SVN下 ...
- Java常用集合类详解
在Java中有一套设计优良的接口和类组成了Java集合框架,使程序员操作成批的数据或对象元素极为方便.所有的Java集合都在java.util包中. 在编写程序的过程中,使用到集合类,要根据不同的需求 ...