【CF449D】Jzzhu and Numbers
提供一个非容斥做法——\(FWT\)
我们发现我们要求的东西就是一个背包,只不过是在\(and\)意义下的
自然有
\]
我们发现这个柿子本质上就是一个和卷积
于是两边取\(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的更多相关文章
- 【LeetCode445】 Add Two Numbers II★★
题目描述: 解题思路: 给定两个链表(代表两个非负数),数字的各位以正序存储,将两个代表数字的链表想加获得一个新的链表(代表两数之和). 如(7->2->4->3)(7243) + ...
- 【LeetCode】386. Lexicographical Numbers 解题报告(Python)
[LeetCode]386. Lexicographical Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【leetcode】Compare Version Numbers
题目描述: Compare two version numbers version1 and version2. If version1 > version2 return 1, if vers ...
- 【leetcode】Add Two Numbers
题目描述: You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- 【leetcode】Compare Version Numbers(middle)
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- 【题解】【链表】【Leetcode】Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 【leetcode】Add Two Numbers(middle) ☆
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 【Leetcode】357. Count Numbers with Unique Digits
题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...
- 【Scala】Scala之Numbers
一.前言 前面已经学习了Scala中的String,接着学习Scala的Numbers. 二.Numbers 在Scala中,所有的数字类型,如Byte,Char,Double,Float,Int,L ...
随机推荐
- 【原】spring redis 缓存注解使用
由于最近新上的项目很多模块没有做数据缓存,大量的请求都会到数据库去查询,为了减轻数据库的压力以及提高网站响应速度,所以在这里采用了spring 提供的注解+redis实现对数据的缓存,主要针对非热点数 ...
- 【redis中键的生存时间(expire) 】
1.redis中可以使用expire命令设置一个键的生存时间,到时间后redis会自动删除它 expire 设置生存时间(单位/秒) pexpire 设置生存时间( ...
- HDU 3501 Calculation 2------欧拉函数变形
Calculation 2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- vue + element ui 阻止表单输入框回车刷新页面
问题 在 vue+element ui 中只有一个输入框(el-input)的情况下,回车会提交表单. 解决方案 在 el-form 上加上 @submit.native.prevent 这个则会阻止 ...
- ASP.NET Core 2 学习笔记(十一)Cookies & Session
基本上HTTP是没有记录状态的协定,但可以通过Cookies将Request来源区分出来,并将部分数据暂存于Cookies及Session,是写网站常用的用户数据暂存方式.本篇将介绍如何在ASP.NE ...
- apply、call、bind有什么区别?
使用 apply var a = { name : "Cherry", func1: function () { console.log(this.name) }, func2: ...
- 浏览器根对象document之数值和布尔属性
1.1 节点类型 ELEMENT_NODE 1 一个 元素 节点,例如 <p> 和 <div>. TEXT_NODE 3 Element 或者 Attr 中实际的文字 PROC ...
- <VS2010>混合模式程序集是针对“v2.0”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集
在把以前写的代码生成工具从原来的.NET3.5升级到.NET4.0时,将程序集都更新后,一运行程序在一处方法调用时报出了一个异常: 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有 ...
- Android设置日期DatePickerDialog
设置日期DatePickerDialog package com.example.testview; import java.util.Calendar; import java.util.Date; ...
- redis介绍(3)RDB和AOF原理解析
简单科普一下redis的概念:(会的可忽略) Redis的概念 redis基于内存的Key Value类型的NoSQL数据库. Redis的特点 1. Redis是一个高性能的Key/Value数据库 ...