题目

提供一个非容斥做法——\(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. js遇到的问题

    一些开发前台时遇到的小问题: ----------------------------------------- 一眼看出页面使用html还是html5: html有三种声明方式:<!DOCTY ...

  2. Win10+Ubuntu双系统安装

    笔者使用的是华硕FX50J装的双系统,之前使用过Dell的游闸安装过,但是没有碰到那么多问题.所以觉得有必要记录下.安装双系统之前,电脑先安装了win10(win10也崩过几次).下面开始安装双系统步 ...

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

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

  4. Spring 配置数据源之一三兄弟

    前期的准备工作,我们是使用的是maven,我们下载节点即可... 节点如下: <dependency> <groupId>org.springframework</gro ...

  5. sql 脚本 oracle scott 用户的四张表导入 mysql 中

    /* 要先删除emp表,不能先删除dept表,因为dept有一个外键关联emp表*/drop TABLE emp;drop TABLE dept; drop TABLE salgrade;drop T ...

  6. clean-css

    What is clean-css? Clean-css is a fast and efficient Node.js library for minifying CSS files. Accord ...

  7. bootstrap作为mixin库的应用模式

    Bootstrap作为一个非常流行的前端css框架,得到了非常多的应用.一般的使用方法都是直接download bootstrap.css,作为css文件引入到html的markup中,随后直接引用其 ...

  8. layui和bootstrap对比

    layui和bootstrap 对比 这两个都属于UI渲染框架. layui是国人开发的一套框架,2016年出来的,现在已更新到2.X版本了.比较新,轻量级,样式简单好看. bootstrap 相对来 ...

  9. Request URL参数

    登录跳转完整参考: http://www.cnblogs.com/dreamer-fish/p/5435274.html request.META.get('HTTP_REFERER', '/') # ...

  10. java+redis+lua生成自动增长的ID序列号

    1.编写lua脚本用于生成主键ID序列号,内容如下 local key = tostring(KEYS[1]); local count = tonumber(KEYS[2]); local date ...