题目

提供一个非容斥做法——\(FWT\)

我们发现我们要求的东西就是一个背包,只不过是在\(and\)意义下的

自然有

\[dp_{i,j}=\sum_{k\&a_i=j}dp_{i-1,k}+dp_{i-1,j}
\]

我们发现这个柿子本质上就是一个和卷积

于是两边取\(fwt\),我们就可以得到一个暴力\(fwt\)的代码

for(re int i=1;i<=n;i++) {
memset(A,0,sizeof(A));
A[a[i]]=1;Fwtand(A,1);
for(re int j=0;j<len;j++) S[j]=S[j]+S[j]*A[j];
}
Fwtand(S,-1);

我们发现其实\(fwt\)的正向变换求得是超集和,又因为我们这里只有一个\(A[a[i]]=1\),所以所有\(A_j\)最多就是\(1\),\(A_j=1\)的时候会使得\(S_j\)翻倍,所以整体下来我们只需要关心\(S_j\)翻了多少倍

显然有多个\(a_i\)是\(j\)的超集就能翻多少倍,于是我们对\(A\)整体来一个\(fwt\)就好了

但是非常蛇皮的一点就是当\(a\)全是\(0\)的时候会把空集算入答案,因此需要特判一下

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int maxn=2500005;
const int mod=1e9+7;
inline int read() {
char c=getchar();int x=0;while(c<'0'||x>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int len,n,M;
LL S[maxn],A[maxn],a[maxn],pw[maxn];
inline void Fwt(LL *f,int o,int mod) {
for(re int i=2;i<=len;i<<=1)
for(re int ln=i>>1,l=0;l<len;l+=i)
for(re int x=l;x<l+ln;++x)
f[x]+=o*f[ln+x],f[x]=(f[x]+mod)%mod;
}
int main() {
n=read();
for(re int i=1;i<=n;i++) a[i]=read(),M=max(M,a[i]);
len=1;while(len<=M) len<<=1;
pw[0]=1;
for(re int i=1;i<=n;i++) pw[i]=(pw[i-1]+pw[i-1])%mod;
for(re int i=1;i<=n;i++) A[a[i]]++;
Fwt(A,1,mod-1);
for(re int i=0;i<len;i++) A[i]=pw[A[i]];
Fwt(A,-1,mod);
if(A[0]==pw[n]) std::cout<<A[0]-1;
else std::cout<<A[0];
return 0;
}

【CF449D】Jzzhu and Numbers的更多相关文章

  1. 【LeetCode445】 Add Two Numbers II★★

    题目描述: 解题思路: 给定两个链表(代表两个非负数),数字的各位以正序存储,将两个代表数字的链表想加获得一个新的链表(代表两数之和). 如(7->2->4->3)(7243) + ...

  2. 【LeetCode】386. Lexicographical Numbers 解题报告(Python)

    [LeetCode]386. Lexicographical Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  3. 【leetcode】Compare Version Numbers

    题目描述: Compare two version numbers version1 and version2. If version1 > version2 return 1, if vers ...

  4. 【leetcode】Add Two Numbers

    题目描述: You are given two linked lists representing two non-negative numbers. The digits are stored in ...

  5. 【leetcode】Compare Version Numbers(middle)

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  6. 【题解】【链表】【Leetcode】Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  7. 【leetcode】Add Two Numbers(middle) ☆

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  8. 【Leetcode】357. Count Numbers with Unique Digits

    题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...

  9. 【Scala】Scala之Numbers

    一.前言 前面已经学习了Scala中的String,接着学习Scala的Numbers. 二.Numbers 在Scala中,所有的数字类型,如Byte,Char,Double,Float,Int,L ...

随机推荐

  1. Hive,HANA可视化客户端工具

    目前市面上的Hive可视化客户端工具,大都是C/S模式的,安装使用都不是太方便,目前有一款基于WEB的可视化工具TreeSoft,通过浏览器就可以访问使用了,并且可以同时管理.维护.监控MySQL,O ...

  2. ibatis中$和#的区别

    比如当变量name的类型是Stirng时, $name$ 打印出来的是 张三 #name# 打印出来的是 ‘张三’ $ 的作用实际上是字符串拼接 #用于变量替换 那什么时候用$,什么时候 用 # (1 ...

  3. C#的字节与流

    计算机中文件有很多种,我们知道实际存在计算机中的都是二进制.这里我记录了通过流对文件的读取操作. 一.首先在这里简单涉及下位,字节,字符的概念. 位(bit):可以表示0或1: 字节(byte):由8 ...

  4. Jquery实现form表单提交后局部刷新页面的多种方法

    最近做一个小项目,刚好需要用到搜索功能,实现搜索框内输入数据然后按回车或者点击“提交”,然后给后台数据库处理并返回数据给前端,在前端局部更新数据. 但是遇到了一个小问题,就是form表单下任意输入框输 ...

  5. python学习之老男孩python全栈第九期_数据库day003知识点总结 —— MySQL数据库day3

    复习: 1. 增 insert into xx(name) values('root'),('xxx'); insert into xx(name) select id from tb1; 2. 自增 ...

  6. python中垃圾回收机制

    Python垃圾回收机制详解   一.垃圾回收机制 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺陷是循环引用的问题.在Python中,如果一个对象的引用数为0,Python虚拟 ...

  7. 数组原型方法调用及函数apply调用时 类数组参数在IE8下的问题

    当函数以 apply 方式调用时, 传参方式是一个由各个参数组成的数组或类数组(一个有length属性的对象),传入参数个数取决于 length 的值,例如,某个对象 args.length=3; a ...

  8. 关于CSS的知识

    这两天在学习关于HTML的知识,今天学习到CSS的知识,将自己所收获的知识点归纳一下: 首先, CSS声明学习:                 1.在head标签中使用style标签声明:      ...

  9. IOT安全

    相关资源 IOT 漏洞 top 10 https://xz.aliyun.com/t/2278 https://www.owasp.org/images/8/8e/Infographic-v1.jpg ...

  10. get_digits

    # coding=utf-8# 一.def digits(n): list1 = [] for each in n: list1.append(each) return list1print(digi ...