题目链接

hdu6057

题意

给出序列\(A[0...2^{m} - 1]\)和\(B[0...2^{m} - 1]\),求所有

\[C[k] = \sum\limits_{i \; and \; j = k} A[i \; xor \; j]B[i \; or \; j]
\]

题解

我只能感叹太神了

看到题目我是懵逼的

首先注意三者运算的关系:

\[(i \; and \; j) + (i \; xor \; j) = (i \; or \; j)
\]

证明显然

于是我们枚举\(x = i \; or \; j,y = i \; xor \; j\),显然\(y \in x\)即\(x \; and \; y = y\)

且对于同一个\(x,y\),这样的\(i,j\)存在\(2^{bit(y)}\)对,\(bit(y)\)指\(y\)二进制下\(1\)的个数

证明显然

于是我们有

\[\begin{aligned}
C[k] &= \sum\limits_{i \; and \; j = k} A[i \; xor \; j]B[i \; or \; j] \\
&= \sum\limits_{x - y = k} [x \; and \; y = y]B[x]A[y]2^{bit(y)} \\
&= \sum\limits_{x \; xor \; y = k} [bit(x) - bit(y) = bit(k)]B[x]A[y]2^{bit(y)} \\
\end{aligned}
\]

除去中间那个限制,就是一个异或卷积了

考虑如何去掉中间的限制,我们只需将\(bit()\)不同的位置分离,分别做\(FWT\)

即设\(F(A,x)_{i} = [bit(i) = x]A_i\)

那么有

\[F(C,k) = \sum\limits_{i = k}^{m} F(B,i) \times F(A,i - k)
\]

然后\(C[k]\)的结果就存在\(F(C,bit(k))\)中

复杂度\(O(m^2 2^{m})\)

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = (1 << 19),maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
return flag ? out : -out;
}
const int P = 998244353;
int m,A[21][maxn],B[21][maxn],C[21][maxn],a[maxn],b[maxn],inv2,deg;
inline int qpow(int a,int b){
int re = 1;
for (; b; b >>= 1,a = 1ll * a * a % P)
if (b & 1) re = 1ll * re * a % P;
return re;
}
inline int bit(int x){int re = 0; while (x) re += (x & 1),x >>= 1; return re;}
inline void fwt(int* a,int n,int f){
for (int i = 1; i < n; i <<= 1)
for (int j = 0; j < n; j += (i << 1))
for (int k = 0; k < i; k++){
int x = a[j + k],y = a[j + k + i];
a[j + k] = (x + y) % P,a[j + k + i] = (x - y + P) % P;
if (f == -1) a[j + k] = 1ll * a[j + k] * inv2 % P,a[j + k + i] = 1ll * a[j + k + i] * inv2 % P;
}
}
int main(){
inv2 = qpow(2,P - 2);
m = read(); deg = (1 << m); int x;
for (int i = 0; i < deg; i++){
a[i] = read(); x = bit(i);
A[x][i] = 1ll * a[i] * qpow(2,x) % P;
}
for (int i = 0; i < deg; i++){
b[i] = read();
B[bit(i)][i] = b[i];
}
for (int i = 0; i <= m; i++){
fwt(A[i],deg,1);
fwt(B[i],deg,1);
}
for (int k = 0; k <= m; k++){
for (int x = k; x <= m; x++)
for (int i = 0; i < deg; i++)
C[k][i] = (C[k][i] + 1ll * B[x][i] * A[x - k][i] % P) % P;
}
for (int i = 0; i <= m; i++) fwt(C[i],deg,-1);
int ans = 0,tmp = 1;
for (int i = 0; i < deg; i++)
ans = (ans + 1ll * C[bit(i)][i] * tmp % P) % P,tmp = 1ll * tmp * 1526 % P;
printf("%d\n",ans);
return 0;
}

hdu6057 Kanade's convolution 【FWT】的更多相关文章

  1. [HDU6057] Kanade‘s convolution (FWT)

    题面 出自HDU6057 给你两个数列 A [ 0... 2 m − 1 ] A[0...2^m-1] A[0...2m−1] 和 B [ 0... 2 m − 1 ] B[0...2^m-1] B[ ...

  2. HDU 6057 Kanade's convolution(FWT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6057 [题目大意] 有 C[k]=∑_(i&j=k)A[i^j]*B[i|j] 求 Ans ...

  3. LOJ2269 [SDOI2017] 切树游戏 【FWT】【动态DP】【树链剖分】【线段树】

    题目分析: 好题.本来是一道好的非套路题,但是不凑巧的是当年有一位国家集训队员正好介绍了这个算法. 首先考虑静态的情况.这个的DP方程非常容易写出来. 接着可以注意到对于异或结果的计数可以看成一个FW ...

  4. CSU1911 Card Game 【FWT】

    题目链接 CSU1911 题解 FWT模板题 #include<algorithm> #include<iostream> #include<cstdlib> #i ...

  5. BZOJ4589 Hard Nim 【FWT】

    题目链接 BZOJ4589 题解 FWT 模板题 #include<algorithm> #include<iostream> #include<cstdlib> ...

  6. [JZOJ6088] [BZOJ5376] [loj #2463]【2018集训队互测Day 1】完美的旅行【线性递推】【多项式】【FWT】

    Description Solution 我们考虑将问题一步步拆解 第一步求出\(F_{S,i}\)表示一次旅行按位与的值为S,走了i步的方案数. 第二步答案是\(F_{S,i}\)的二维重复卷积,记 ...

  7. 【杂题】[AGC034F] RNG and XOR【集合幂级数】【FWT】【DP】

    Description 你有一个随机数生成器,它会以一定的概率生成[0,2^N-1]中的数,每一个数的概率是由序列A给定的,Pi=Ai/sum(Ai) 现在有一个初始为0的数X,每一轮随机生成一个数v ...

  8. CF662C Binary Table【FWT】

    CF662C Binary Table 题意: 给出一个\(n\times m\)的\(01\)矩阵,每次可以反转一行或者一列,问经过若干次反转之后,最少有多少个\(1\) \(n\le 20, m\ ...

  9. CF1119H-Triple【FWT】

    正题 题目链接:https://www.luogu.com.cn/problem/CF1119H 题目大意 \(n\)个可重集,第\(i\)个里有\(x\)个\(a_i\),\(y\)个\(b_i\) ...

随机推荐

  1. C/S结构与B/S结构

    按照是否需要访问网络,程序可分为网络程序与非网络程序.其中网络程序又可分为B/S结构与C/S结构. C/S结构是指客户端(Client)/服务器(Server)模式,这种模式的客户端中 需要安装一个R ...

  2. LeetCode 192. Word Frequency

    分析 写bash,不太会啊…… 难度 中 来源 https://leetcode.com/problems/word-frequency/ 题目 Write a bash script to calc ...

  3. if _ else if _ else,case,程序逻辑判断- java基础

    //单个判端 if(){ } //双判端 if(){ }else{ } //多重判端 if(){ }else if(){ }else if(){ }else{ } package test1; // ...

  4. Hyperledger Fabric Ledger——账本总账

    Ledger Ledger(账本)即所有的state transitions(状态切换),是有序且不可篡改的.state transitions(状态切换)是由参与方提交的chaincode(智能合约 ...

  5. Kubernetes网络方案 Flannel和calico

    摘抄某博客 1.   Flannel Flannel是为kubernetes设计的一个非常简洁的多节点三层网络方案,解决不同host上的容器互联问题,原理是为每个host分配一个subnet,容器从此 ...

  6. 服务端模版注入漏洞检测payload整理

    服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...

  7. Nginx中server_name 参数详解

    Nginx中的server_name指令主要用于配置基于名称的虚拟主机,server_name指令在接到请求后的匹配顺序分别为: 1.准确的server_name匹配,例如: server { lis ...

  8. Final发布文案+美工

    团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/(组长) 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www ...

  9. Daily Scrum10 11.14

    昨天的任务已经完成,但是我们在完成任务的过程中确实遇到了困难.昨天我们发现无法连接sqlserver的时候,给罗杰老师发了邮件.老师也给我们提出了建议,给我们提供了一些参考.所以今天大家都在研究如何解 ...

  10. [2019BUAA软件工程]第0次个人作业

    我 & 计算机 写在前面   撰写本博客时,笔者正就读北航计算机系大三下的软件工程课程.借由这次博客作业的机会,笔者从高考时与计算机专业结缘.大学对计算机的学习以及对未来的计划三方面进行了些许 ...