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 ...
随机推荐
- Java源码解析——集合框架(四)——LinkedListLinkedList原码分析
LinkedList源码分析 LinkedList也和ArrayList一样实现了List接口,但是它执行插入和删除操作时比ArrayList更加高效,因为它是基于链表的.基于链表也决定了它在随机访问 ...
- 服务器空间不足导致mysql服务器无法运行
今天有朋友请我帮忙解决一个问题,他公司服务器mysql数据库一直连接失败.登录服务期之后发现服务器空间占满了,导致mysql不能启动. 下面说解决方法: 首先查看空间占用,发现空间占满了 df -h ...
- 带cookie请求数据
经常会用到一些采集网上的资源,普通网站很好采,get_file_contents()/c_url(). 有的网站会有登陆后才能采集,需要带cookie请求获取(登陆网站相同方法),下面记录一下使用方法 ...
- Python学习:1.快速搭建python环境
一.安装python 现在python有两个比较大的版本一个是python3.x一个是python2.x,python3.x相当于与python2.x是一个比较大的升级,但是python3.x没有向下 ...
- ruby OpenURI模块使用
OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP(OpenURI支持重定向) 像打开普通文件那样打开ht ...
- TopCoder SRM 489 Div1 Lev3:AppleTree
挺优秀的一道题,想出做法时有些惊艳. 题意: 数轴上有\(D\)个连续整数刻度,有\(N\)棵树要种在这些刻度上,其中第\(i\)棵与两旁(如果有的话)相邻的树至少要相距\(R_i\),问方法数. \ ...
- java 获取图片大小(尺寸)
1,获取本地图片大小(尺寸) File picture=new File(strSrc);BufferedImage sourceImg=ImageIO.read(new FileInputStrea ...
- poj1050 dp动态规划
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- Mac OS下搭建Hadoop + Spark集群
首先注意版本兼容问题!!!本文采用的是Scala 2.11.8 + Hadoop 2.7.5 + Spark 2.2.0 请在下载Spark时务必看清对应的Scala和Hadoop版本! 一.配置JD ...
- 美年健康股票成交量和K线关系
看下美年健康的股票,这次主要是研究下成交量和K线的关系,以最后5天为例子,股票下跌成交量降低,说明抛压很小,在最后3天,价格突破的时候,成交量是平时的两倍,说明有机构买入, 业绩部分还可以,全民健身是 ...