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 ...
随机推荐
- MySQL版本详解
一.版本说明 1.1.MySQL相关连接 MySQL官网:https://www.mysql.com/ MySQL下载:https://dev.mysql.com/downloads/mirrors/ ...
- php sign签名实例
1:实现签名代码: /** * 签名生成算法 * @param array $params API调用的请求参数集合的关联数组,不包含sign参数 * @param string $secret 签名 ...
- Hive初识(一)
LOAD DATA语句 一般来说,在SQL创建表后,我们就可以使用INSERT语句插入数据.但在Hive中,可以使用LOAD DATA语句来插入数据. LOAD DATA [LOCAL] INPATH ...
- 【struts2】struts2的使用
1.使用步骤 1) 导入struts2的支持jar包 名称 说明 struts2-core-2.3.4.1.jar Structs2的核心类库 xwork-core-2.3.4.1.jar xwork ...
- C# 实现窗口无边框,可拖动效果
#region 无边框拖动效果 [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCaptu ...
- java stream 处理分组后取每组最大
有一个需求功能:先按照某一字段分组,再按照另外字段获取最大的那个 Map<String, HitRuleConfig> configMap = configList.parallelStr ...
- 3106: [cqoi2013]棋盘游戏
3106: [cqoi2013]棋盘游戏 链接 分析: 极大极小搜索 + 记忆化. 代码 #include<bits/stdc++.h> using namespace std; type ...
- kafka监听类
package com.datad.dream.service; import com.alibaba.fastjson.JSON; import com.datad.dream.dao.KafkaI ...
- 用es6写一个分数库
es6发布后nodejs开始更新.最近写一些库发现新特性还是很好用的,于是回来写一个分数库练手. 对于es6本身 ... => 以及 array.includes 很简洁.class依然不是很顺 ...
- Spring常用注解用法总结
转自http://www.cnblogs.com/leskang/p/5445698.html 1.@Controller 在SpringMVC 中,控制器Controller 负责处理由Dispat ...