题目链接

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})\)

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<vector>
  7. #include<queue>
  8. #include<cmath>
  9. #include<map>
  10. #define LL long long int
  11. #define REP(i,n) for (int i = 1; i <= (n); i++)
  12. #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
  13. #define cls(s,v) memset(s,v,sizeof(s))
  14. #define mp(a,b) make_pair<int,int>(a,b)
  15. #define cp pair<int,int>
  16. using namespace std;
  17. const int maxn = (1 << 19),maxm = 100005,INF = 0x3f3f3f3f;
  18. inline int read(){
  19. int out = 0,flag = 1; char c = getchar();
  20. while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
  21. while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
  22. return flag ? out : -out;
  23. }
  24. const int P = 998244353;
  25. int m,A[21][maxn],B[21][maxn],C[21][maxn],a[maxn],b[maxn],inv2,deg;
  26. inline int qpow(int a,int b){
  27. int re = 1;
  28. for (; b; b >>= 1,a = 1ll * a * a % P)
  29. if (b & 1) re = 1ll * re * a % P;
  30. return re;
  31. }
  32. inline int bit(int x){int re = 0; while (x) re += (x & 1),x >>= 1; return re;}
  33. inline void fwt(int* a,int n,int f){
  34. for (int i = 1; i < n; i <<= 1)
  35. for (int j = 0; j < n; j += (i << 1))
  36. for (int k = 0; k < i; k++){
  37. int x = a[j + k],y = a[j + k + i];
  38. a[j + k] = (x + y) % P,a[j + k + i] = (x - y + P) % P;
  39. if (f == -1) a[j + k] = 1ll * a[j + k] * inv2 % P,a[j + k + i] = 1ll * a[j + k + i] * inv2 % P;
  40. }
  41. }
  42. int main(){
  43. inv2 = qpow(2,P - 2);
  44. m = read(); deg = (1 << m); int x;
  45. for (int i = 0; i < deg; i++){
  46. a[i] = read(); x = bit(i);
  47. A[x][i] = 1ll * a[i] * qpow(2,x) % P;
  48. }
  49. for (int i = 0; i < deg; i++){
  50. b[i] = read();
  51. B[bit(i)][i] = b[i];
  52. }
  53. for (int i = 0; i <= m; i++){
  54. fwt(A[i],deg,1);
  55. fwt(B[i],deg,1);
  56. }
  57. for (int k = 0; k <= m; k++){
  58. for (int x = k; x <= m; x++)
  59. for (int i = 0; i < deg; i++)
  60. C[k][i] = (C[k][i] + 1ll * B[x][i] * A[x - k][i] % P) % P;
  61. }
  62. for (int i = 0; i <= m; i++) fwt(C[i],deg,-1);
  63. int ans = 0,tmp = 1;
  64. for (int i = 0; i < deg; i++)
  65. ans = (ans + 1ll * C[bit(i)][i] * tmp % P) % P,tmp = 1ll * tmp * 1526 % P;
  66. printf("%d\n",ans);
  67. return 0;
  68. }

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. RabbitMQ入门:路由(Routing)

    在上一篇博客<RabbitMQ入门:发布/订阅(Publish/Subscribe)>中,我们认识了fanout类型的exchange,它是一种通过广播方式发送消息的路由器,所有和exch ...

  2. Mysql启动失败解决方案 - 个人经验可能不适合所有场景

    以前一直用的Mysql5.5,安装程序是一个exe程序,安装完了相应的服务也给我注册好了,然后直接启动连接即可. 最近升级到了8.0.15,发现和以前不一样了. 8.0.15下载地址 安装解压之后目录 ...

  3. gulp: Did you forget to signal async completion? 解决方案

    背景 学习gulp的前端自动化构建,按照示例代码,跑了一个简单的task,控制台打出如下提示: The following tasks did not complete: testGulp Did y ...

  4. IDEA 2018 最新激活码 License server

    IDEA 2018 最新激活码 License server 总会有一个属于适合你的!嘻嘻 http://hb5.s.osidea.cc:1017 http://idea.youbbs.org htt ...

  5. 微软职位内部推荐-Software Engineer II-Senior Software Engineer for Satori

    微软近期Open的职位: Title: Software Engineer II-Senior Software Engineer for Satori, STC Location: Beijing ...

  6. wc命令详解

    基础命令学习目录首页 原文链接:http://www.cnblogs.com/peida/archive/2012/12/18/2822758.html Linux系统中的wc(Word Count) ...

  7. react-native 常规操作

    1.  关闭xcode打开模拟器的快捷键 , 等常规操作 https://www.jianshu.com/p/f6723f3406b7

  8. Oracle中的SQL分页查询原理和方法详解

    Oracle中的SQL分页查询原理和方法详解 分析得不错! http://blog.csdn.net/anxpp/article/details/51534006

  9. Linux常用软件安装与配置——目录

    http://blog.csdn.net/clevercode/article/details/45740431

  10. Scrum立会报告+燃尽图(Final阶段第二次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2481 项目地址:https://coding.net/u/wuyy694 ...