【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. ...
随机推荐
- php 多维数组,根据某个特定字段过滤重复值
//假如 数据是这样的$arr=[ [ 'goods_name'=>'xxx', 'goods_id'=>111,],[ 'goods_name'=>'xxx', 'goods_id ...
- geometry_msgs.msg.PoseStamped 代码示例
https://programtalk.com/python-examples/geometry_msgs.msg.PoseStamped/
- Tkinter 之OptionMenu下拉选择菜单
一.代码示例 import tkinter as tk window = tk.Tk() # 设置窗口大小 winWidth = 600 winHeight = 400 # 获取屏幕分辨率 scree ...
- Visual C++ 6.0精简绿色版下载及简单使用教程
Visual C++ 6.0精简绿色版下载及简单使用教程 Microsoft Visual C++简介 Visual Studio 是微软公司推出的开发环境,Visual Studio 可以用来创建 ...
- 感知机模型到DNN模型
参考资料 感知机模型:https://www.cnblogs.com/pinard/p/6042320.html DNN:https://www.cnblogs.com/pinard/p/641866 ...
- 如何获取UA?
代码: function whatBrowser() { document.Browser.Name.value = navigator.appName; document.Browser.Versi ...
- unless it is in a subquery contained in a HAVING clause or a select list.
sql查询报错: An aggregate may not appear in the WHERE clause unless it is in asubquery contained in a HA ...
- VS Code 使用技巧[转载]
原文:VS Code 快捷键(VS Code Shortcuts.pdf) 常用 General 按 Press 功能 Function Ctrl + Shift + P,F1 显示命令面板 Show ...
- ObjectAnimator简单示例
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- spring的事务是什么?与数据库的事务是否一样
spring的事务是什么?与数据库的事务是否一样 先说一下什么是事务,事务:是对数据库的一些列操作. 之前一直觉得事务只针对于数据库当中,5种隔离级别,7种传播行为,后来才发现这是针对Spring的, ...