题目

提供一个非容斥做法——\(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. dubbo学习思路梳理

    dubbo要解决的问题 rpc调用需要定制.额外的工作量 分布式服务中,服务动辄几十上百,相互之间的调用错综复杂,相互依赖严重 对集群性的服务,需要负载策略 对集群性的服务,能动态扩展节点 dubbo ...

  2. Java:使用DOM4j来实现读写XML文件中的属性和元素

    DOM4可以读取和添加XML文件的属性或者元素 读取属性: public static void ReadAttributes() throws DocumentException { File fi ...

  3. 为 HTTP/2 头压缩专门设计的 HPACK

          HTTP/2 对消息头采用 HPACK 进行压缩传输,能够节省消息头占用的网络的流量.如何理解 HPACK 压缩呢? 如果我们约定将常用的请求头的参数用一些特殊的编号来表示,比如 GET ...

  4. Swift 函数调用到底写不写参数名

    最近真正开始学 Swift,在调用函数的时候遇到一个问题:到底写不写函数名? 我们来看两个个例子: // 1 func test(a: Int, b: Int) ->Int { return a ...

  5. 微信获取openId

    router.beforeEach(function(to, from, next){ //中间页等待跳转 if(to.meta.requireCheck=="WaitLogin" ...

  6. 在element-ui的el-tree组件中用render函数生成el-button

    本文主要介绍怎么在el-tree组件中通过render函数来el-button. 这是element-ui中el-tree树: 这是需要实现的效果: tree.vue文件中,具体实现的代码如下: &l ...

  7. PHP的new self() 与new static()

    参考链接:[PHP中new static()与new self()的区别异同分析],[PHP中new self()和new static()的区别探究],[PHP中static和self的区别] 要点 ...

  8. 快速 图片颜色转换迁移 Color Transfer Opencv + Python

      Super fast color transfer between images About a month ago, I spent a morning down at the beach, w ...

  9. SLAM会被深度学习方法取代吗?

    日益感觉到自己对深度学习的理解比较肤浅,这段且当做是以前的认识. 上上周去围观了泡泡机器人和AR酱联合举办的论坛.在圆桌阶段,章国峰老师提了一个问题:SLAM会被深度学习方法取代吗?这是一个很有趣的话 ...

  10. centos7 yum安装mysql | mariaDb

    mysql解释: mysql数据库是最常用的一种数据库,下面我来在centos7的迷你版上安装一下mysql.绝对纯净的环境哦 centos:    CentOS-7-x86_64-Minimal-1 ...