hdu 6057 Kanade's convolution(子集卷积)
题解:

然后就是接下来如何fwt
也就是如何处理bit(x) - bit(y) = bit(k)这个条件。
其实就是子集卷积。
把bit(x)和bit(y)划分成两个集合,然后就是子集卷积的形式。
这里设两个新的数组 A[bit(y)][y], B[bit(x)][x],代表拆出来的相应数组
然后对这两个数组做fwt,得到其点值表示,然后直接在外层枚举x和y的大小然后做卷积即可。
这样说可能很抽象,其实贴出代码就很清楚了
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
const int MOD = ;
typedef long long LL;
LL mypow(LL a, LL b){
LL ans = ; for(; b; b >>= ) { if(b&) (ans *= a) %= MOD; (a *= a) %= MOD; } return ans;
}
LL I2 = mypow(, MOD-);
const int maxn = (<<) + ;
LL a[maxn], b[maxn], A[][maxn*], B[][maxn*], C[][maxn*];
vector<int> Bit[];
int m; class FWT{
public:
void fwt(LL *a, int n){
for(int d = ; d < n; d <<= ){
for(int m = d<<, i = ; i < n; i += m){
for(int j = ; j < d; j++){
LL x = a[i+j], y = a[i+j+d];
a[i+j] = x+y; if(a[i+j] >= MOD) a[i+j] -= MOD;
a[i+j+d] = x-y; if(a[i+j+d] < ) a[i+j+d] += MOD;
}
}
}
}
void ufwt(LL *a, int n){
for(int d = ; d < n; d <<= ){
for(int m = d<<, i = ; i < n; i += m){
for(int j = ; j < d; j++){
LL x = a[i+j], y = a[i+j+d];
a[i+j] = (x+y)*I2%MOD; a[i+j+d] = (x-y+MOD)*I2%MOD;
}
}
}
}
void work(LL *a, LL *b, int n){
fwt(a, n);
fwt(b, n);
for(int i = ; i < n; i++) a[i] *= b[i];
ufwt(a, n);
}
}myfwt; int bit(int x){
int ans = ;
for(int i = ; i < ; i++)
ans += ((x&(<<i)) > );
return ans;
} int main()
{
for(int i = ; i < (<<); i++) Bit[bit(i)].push_back(i);
cin>>m;
for(int i = ; i < (<<m); i++) scanf("%d", &a[i]);
for(int i = ; i < (<<m); i++) scanf("%d", &b[i]);
int L = (<<m);
for(int i = ; i <= m; i++){
for(auto x : Bit[i]){
if(x >= L) break;
A[i][x] = (a[x]*(<<i))%MOD;
B[i][x] = b[x];
}
myfwt.fwt(A[i], L);
myfwt.fwt(B[i], L);
}
for(int x = ; x <= m; x++)
for(int y = ; y <= x; y++)
for(int i = ; i < L; i++)
(C[x-y][i] += A[y][i]*B[x][i]) %= MOD;
for(int i = ; i <= m; i++) myfwt.ufwt(C[i], L);
LL ans = , t = ;
for(int i = ; i < (<<m); i++){
(ans += C[bit(i)][i]*t) %= MOD;
(t *= ) %= MOD;
}
cout<<ans<<endl;
return ;
}
hdu 6057 Kanade's convolution(子集卷积)的更多相关文章
- HDU 6057 - Kanade's convolution | 2017 Multi-University Training Contest 3
/* HDU 6057 - Kanade's convolution [ FWT ] | 2017 Multi-University Training Contest 3 题意: 给定两个序列 A[0 ...
- 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 ...
- HDU 6057 Kanade's convolution
题目链接:HDU-6057 题意: 思路:先按照官方题解推导出下面的式子: 现在唯一的问题就是怎么解决[bit(x)-bit(y)=bit(k)]的问题. 我们定义\( F(A,k)_{i}=\lef ...
- @总结 - 2@ 位运算卷积/子集卷积 —— FWT/FMT
目录 @0 - 参考资料@ @1 - 异或卷积概念及性质@ @2 - 快速沃尔什正变换(异或)@ @3 - 快速沃尔什逆变换(异或)@ @4 - 与卷积.或卷积@ @5 - 参考代码实现@ @6 - ...
- ufldl学习笔记和编程作业:Feature Extraction Using Convolution,Pooling(卷积和汇集特征提取)
ufldl学习笔记与编程作业:Feature Extraction Using Convolution,Pooling(卷积和池化抽取特征) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰 ...
- Group Convolution分组卷积,以及Depthwise Convolution和Global Depthwise Convolution
目录 写在前面 Convolution VS Group Convolution Group Convolution的用途 参考 博客:blog.shinelee.me | 博客园 | CSDN 写在 ...
- CF914G Sum the Fibonacci FWT、子集卷积
传送门 一道良心的练习FWT和子集卷积的板子-- 具体来说就是先把所有满足\(s_a \& s_b = 0\)的\(s_a \mid s_b\)的值用子集卷积算出来,将所有\(s_a \opl ...
- CF 914G Sum the Fibonacci——子集卷积
题目:http://codeforces.com/contest/914/problem/G 第一个括号可以子集卷积:第三个括号可以用 FWT 异或卷积:这样算出选两个数组成 x 的方案数:三个部分的 ...
- UOJ 348 【WC2018】州区划分——子集卷积
题目:http://uoj.ac/problem/348 参考:https://www.cnblogs.com/NaVi-Awson/p/9242645.html#%E5%AD%90%E9%9B%86 ...
随机推荐
- Co. - Microsoft - Windows - Dos命令
DOS命令 cd .. 是进入上一层目录,cd \ 是进入根目录 我们来重申下%~dp0和%cd%的区别, %cd%和%~dp0都能用来表示当前目录,但是他们在不同的使用场景下,功能却不相同: %cd ...
- java 时间转换去杠
public static String minusHyphen(String dateParam){ if(dateParam ==null) return null; if(dateParam.i ...
- vue组件中的样式属性--scoped
Scoped CSS Scoped CSS规范是Web组件产生不污染其他组件,也不被其他组件污染的CSS规范. vue组件中的style标签标有scoped属性时表明style里的css样式只适用于当 ...
- flask之route中的参数
flask的路由中有一些参数 使用案例 from flask import Flask, render_template, url_for, session, request, redirect ap ...
- 模块的使用与orm简介
目录 1 django中app的概念: 2 模板路径配置: 3 静态文件配置: 4 完整版登录功能 5 get请求和post请求 6 新手三件套总结 7 pycharm连接mysql 8 orm介绍 ...
- ctf题目writeup(3)
题目地址: https://www.ichunqiu.com/battalion 1. 这个是个mp3,给的校验是为了下载下来的. 下来之后丢进audicity中 放大后根据那个音块的宽度来确定是 . ...
- 高德API+.NET解决租房问题(可能是最可靠房源:上海互助租房)
作者:李国宝链接:https://zhuanlan.zhihu.com/p/22113421来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. PS:最近点赞和关注的小伙伴 ...
- nginx+tomcat 反向代理 负载均衡配置
1.nginx的安装和配置见:http://www.cnblogs.com/ll409546297/p/6795362.html 2.tomcat部署项目到对应的服务器上面并启动,不详解 3.在ngi ...
- Spring研磨分析、Quartz任务调度、Hibernate深入浅出系列文章笔记汇总
Spring研磨分析.Quartz任务调度.Hibernate深入浅出系列文章笔记汇总 置顶2017年04月27日 10:46:45 阅读数:1213 这系列文章主要是对Spring.Quartz.H ...
- 涉及到大小变化,类似QScrollArea判断大小是否显示滚动条
涉及到大小变化,类似QScrollArea判断大小是否显示滚动条的情况要注意 这两个属性的设置: