【51nod】1407 与与与与
【51nod】1407 与与与与
设\(f(x)\) 为\(A_{i} \& x == x\)的\(A_{i}\)的个数
设\(g(x)\)为\(x\)里1的个数
\(\sum_{i = 0}^{2^{20}} (-1)^{g(x)}2^{f(x)}\)
\(f(x)\)就是按位取反之后的一个FMT卷积,把判断条件改成这一位不存在即可
也可以用FWT的与卷积直接卷起来
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int a[(1 << 20) + 5],cnt[(1 << 20) + 5],pw[1000005];
int lowbit(int x) {
return x & (-x);
}
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
void Solve() {
memset(a,0,sizeof(a));
int d;
pw[0] = 1;
for(int i = 1 ; i <= N ; ++i) {
read(d);a[d]++;
pw[i] = mul(pw[i - 1],2);
}
for(int j = 0 ; j < 20 ; ++j) {
for(int S = (1 << 20) - 1 ; S >= 0 ; --S) {
if(!((S >> j) & 1)) {
a[S] += a[S ^ (1 << j)];
}
}
}
int ans = 0;
for(int S = 0 ; S < (1 << 20) ; ++S) {
if(S) cnt[S] = cnt[S - lowbit(S)] + 1;
int t;
if(cnt[S] & 1) t = MOD - 1;
else t = 1;
update(ans,mul(t,pw[a[S]]));
}
out(ans);enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
while(scanf("%d",&N) != EOF) Solve();
}
【51nod】1407 与与与与的更多相关文章
- 51nod 最近刷题 简要题解
51nod 1564 由于数据是随机的,可以证明,对于每一个数,向左或右找比它小的数,长度是logn级别的 考虑枚举最大值 注意,对于每一个最大值,如果直接用2个循环枚举左右端点的话,理论是lognl ...
- NOIP前做题记录
鉴于某些原因(主要是懒)就不一题一题写了,代码直接去\(OJ\)上看吧 CodeChef Making Change 传送门 完全没看懂题解在讲什么(一定是因为题解公式打崩的原因才不是曲明英语太差呢- ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- 【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间 ...
- 【51Nod 1622】【算法马拉松 19C】集合对
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio&g ...
- 【51Nod 1616】【算法马拉松 19B】最小集合
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. ...
随机推荐
- [Go] 基础系列一: for-select中的break、continue和return
break select中的break,类似c系列中的break,break后的语句不执行 for和select一同使用,有坑 break只能跳出select,无法跳出for package test ...
- 读取文件名.cpp
#include <io.h> #include <iostream> #include <string> #include <windows.h> # ...
- Mac下不能成功打开uiautomatorviewer的问题解决
在终端运行uiautomatorviewer之后出现下面的错误,检查以后发现环境变量也配置好了 Error: Could not create the Java Virtual Machine. Er ...
- PyTricks-函数参数的解包操作
def myfunc(x, y, z): print(x, y, z) tuple_vec = (1, 0, 1) dict_vec = {'x': 1, 'y': 0, 'z': 1} >&g ...
- PHPStorm 快捷键大全(Win/Linux/Mac)
下面的-符号记得改成 ‘`’,markdown 语法会转义.使用频率是我自己为准.仅供参考 Mac 符号 符号 解释 ⌘ Command ⇧ Shift ⌃ Control ↩ Enter/Ret ...
- Cross-Site Request Forgery (CSRF)
https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF) Overview Cross-Site Request Forger ...
- 通过phpMyAdmin优化mysql 数据库可能存在的问题
通过phpMyAdmin优化mysql 数据库可能存在的问题 文章来源:外星人来地球 欢迎关注,有问题一起学习欢迎留言.评论
- 在Linux下使用LLVM Clang以及Blocks
可以从这个链接下载:http://llvm.org/releases/download.html sudo apt-get install llvm sudo apt-get install clan ...
- 012-多线程-JUC集合-Queue-SynchronousQueue和LinkedTransferQueue
一.SynchronousQueue概述 SynchronousQueue是一个不存储元素的队列.每一个put操作必须等待一个take操作,否则不能继续添加元素. 它支持公平访问队列.默认情况下线程采 ...
- node.js连接DB2实现fetchRows一行一行获取sql的源码
参见程序中的queryResult那部分: /* * This example demonstrates how to fetch a single row from a large table * ...