【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. ...
随机推荐
- BigDecimal进行除法运算时的坑
循环小数输出的坑 BigDecimal做除法时如果出现除不尽(循环小数)的情况,会抛异常: BigDecimal a = new BigDecimal("1"); System ...
- centos7 安装anaconda3
在学习Python的时候,如果学习python3的版本,那么需要重新安装pytho3,因为系统默认的Python版本是python2,当然,有的可能需要同时保留两个版本,这里来试着使用一下anacon ...
- Windows下OpenFOAM开发及使用环境配置指南 (1)【转载】
转载自:http://openfoam.blog.sohu.com/158614863.html *************************************************** ...
- 记录一次腾讯X5内核64位手机初始化失败
之前一直在使用x5内核,只需要一个jar包和so文件就能让webview实现多余原生webview的水平,在32位的手机上能够正常运行,但是到了64位手机上就报如下错误: E/ERROR:: .... ...
- 亚马逊AWS服务器CentOS/Linux系统Shell安装Nginx及配置自启动
领了一个亚马逊的1年免费服务器,今天尝试安装 Nginx 服务器,使用原生的 Shell 方法. 为了方便以后查看,就把过程记录一下. 注意:亚马逊(AWS)服务器默认只能用 user-ec2 账户进 ...
- maven install的时候把源码一起放到仓库
在pom.xml中加入插件 <build> <plugins> <!-- Source attach plugin --> < ...
- mac、windows、linux版jdk1.8下载
链接: https://pan.baidu.com/s/1Yjs6GIxURiocq30zZ7heYQ 提取码: g6i8
- mybatis 的 <![CDATA[ ]]> 标签作用
有个细节一直没有注意到,今天mark一下: mybatis进行时间比较的时候我们会这么写,一直都是在复制粘贴所以没有注意,一个标签<![CDATA[ ]]> 今天在做另外一个有时间比较sq ...
- Swift_IOS之提示框UIAlertController
import UIKit class ViewController: UIViewController ,UIActionSheetDelegate{ @IBAction func btn1(_ se ...
- com.alibaba.fastjson.JSONObject;的使用
转: com.alibaba.fastjson.JSONObject;的使用 2018-11-04 23:51:23 mameng1998 阅读数 6404更多 分类专栏: java 1 POM ...