【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 与与与与的更多相关文章

  1. 51nod 最近刷题 简要题解

    51nod 1564 由于数据是随机的,可以证明,对于每一个数,向左或右找比它小的数,长度是logn级别的 考虑枚举最大值 注意,对于每一个最大值,如果直接用2个循环枚举左右端点的话,理论是lognl ...

  2. NOIP前做题记录

    鉴于某些原因(主要是懒)就不一题一题写了,代码直接去\(OJ\)上看吧 CodeChef Making Change 传送门 完全没看懂题解在讲什么(一定是因为题解公式打崩的原因才不是曲明英语太差呢- ...

  3. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  4. 51Nod 1268 和为K的组合

    51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...

  5. 51Nod 1428 活动安排问题

    51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...

  6. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

  7. 【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间 ...

  8. 【51Nod 1622】【算法马拉松 19C】集合对

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio&g ...

  9. 【51Nod 1616】【算法马拉松 19B】最小集合

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. ...

随机推荐

  1. java23种设计模式等等。。

    23种设计模式http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html 提升Java代码性能和安全性https://blog ...

  2. C++中的平方、开方、绝对值怎么计算

    #include <math.h> //平方 pow() ,);// 4的平方=16 //开方 ,0.5);// 4的平方根=2 );// 4的平方根=2 //整数绝对值 int c = ...

  3. MySQL 5.7:聊聊sql_mode

    1.sql_mode=only_full_group_by 导致的语法错误问题 MySQLSyntaxErrorException Caused by: com.mysql.jdbc.exceptio ...

  4. kvm 学习(二)镜像

    Linux下 如何通过命令行使用现有的镜像创建.启动kvm虚拟机 这里假定已经创建好了相应的镜像: eg:我这里制作的镜像名称为zu1-centos7.img # ls zu1-centos7.img ...

  5. (转)centos7安装telnet服务

    借鉴:https://www.cnblogs.com/daipenglin/p/4934572.html 阅读目录 1 CentOS7.0 telnet-server 启动的问题 场景:在进行Teln ...

  6. avalon background-image写法

    ms-css="{backgroundImage: 'url('+reportdata.avatar + ')'}"

  7. NSCTF 2017-pwn2

    目录 程序基本信息 程序漏洞 整体思路 exp脚本 发现的问题 内容参考 程序基本信息 32位动态链接程序,开启了数据段不可执行以及栈溢出保护 程序漏洞 在函数中sub_80487fa中有一个格式化字 ...

  8. [RK3399] Type-C改为MicroUSB

    CPU:RK3399 系统:Android 7.1.2 为了降低成本,主板将 Type-C 改为 MicroUSB 接口,节省了 fusb302芯片 参考 Rockchip 的官方文档第4部分:Mic ...

  9. OPPO数据中台之基石:基于Flink SQL构建实数据仓库

    小结: 1. OPPO数据中台之基石:基于Flink SQL构建实数据仓库 https://mp.weixin.qq.com/s/JsoMgIW6bKEFDGvq_KI6hg 作者 | 张俊编辑 | ...

  10. android: requestLayout(), invalidate(), postInvalidate() 方法区别

    一.invalidate和postInvalidate 这两个方法都是在重绘当前控件的时候调用的.invalidate在UI线程中调用,postInvalidate在非UI线程中调用.因为androi ...