Codeforces 662C Binary Table FWT 快速沃尔什变换
来源:互联网 发布:mysql私房菜深入浅出 编辑:程序博客网 时间:2024/05/18 00:07
大家都很强, 可与之共勉 。
题意:
给出一个
题解:
我们会发现行数很小,是一个可以状态压缩的范围(滑稽)。
于是我萌就状压行
对于每一列,用
用
然后我们考虑如何实现操作。可以确定的一点是操作奇数次相当于操作一次,偶数次相当于不操作。
我们继续状压操作,令
于是我们枚举每一种行的操作
于是可得到
怎么优化呢?由异或的性质:
再由异或的性质:
于是这个东西叫做异或卷积,她可以用
最后取出
# include <bits/stdc++.h>struct FastWalshHadamardTransform { void dwt ( long long* a, int n ) { for ( int d = 1 ; d < n ; d <<= 1 ) { for ( int m = d << 1, i = 0 ; i < n ; i += m ) { for ( int j = 0 ; j < d ; ++ j ) { long long x = a [i + j], y = a [i + j + d] ; a [i + j] = x + y, a [i + j + d] = x - y ; //and a[i+j] = x+y; //or a[i+j+d] = x+y; } } } } void idwt ( long long* a, int n ) { for ( int d = 1 ; d < n ; d <<= 1 ) { for ( int m = d << 1, i = 0 ; i < n ; i += m ) { for ( int j = 0 ; j < d ; ++ j ) { long long x = a [i + j], y = a [i + j + d] ; a [i + j] = ( x + y ) >> 1, a [i + j + d] = ( x - y ) >> 1 ; //and a[i+j] = x-y //or a[i+j+d] = y-x } } } } void main ( long long* a, long long* b, long long* res, int n ) { dwt ( a, n ) ; dwt ( b, n ) ; for ( int i = 0 ; i < n ; ++ i ) res [i] = a [i] * b [i] ; idwt ( res, n ) ; }} fwt ;const int L = 1 << 22 ;char mat [22] [100010] ;long long a [L], b [L], c [L] ;int main ( ) { int n, m ; scanf ( "%d%d", & n, & m ) ; for ( int i = 0 ; i < n ; ++ i ) scanf ( "%s", mat [i] ) ; for ( int i = 0 ; i < m ; ++ i ) { int state ( 0 ) ; for ( int j = 0 ; j < n ; ++ j ) state |= ( mat [j] [i] == '1' ) << j ; ++ a [state] ; } for ( int i = 0, lim = 1 << n ; i < lim ; ++ i ) { b [i] = std :: min ( __builtin_popcount ( i ), n - __builtin_popcount ( i ) ) ; } fwt.main ( a, b, c, 1 << n ) ; std :: cout << *std :: min_element ( c, c + ( 1 << n ) ) << std :: endl ; return 0 ;}
阅读全文
0 0
- Codeforces 662C Binary Table 快速沃尔什变换(FWT)
- Codeforces 662C Binary Table FWT 快速沃尔什变换
- 快速沃尔什变换FWT
- CodeForces 663E - Binary Table FWT
- [FWT] Codeforces 663E. Binary Table
- [FWT] Codeforces663E .Binary Table
- [ FWT ] Codeforces663E Binary Table
- [FWT] 快速沃尔什变换学习笔记
- FWT——快速沃尔什变换
- 快速沃尔什变换(FWT) 学习笔记
- 快速沃尔什变换详解(FWT)
- 文章标题 FWT (快速沃尔什变换) 模板
- 快速沃尔什变换(FWT)讲解 解决集合卷积的方法
- CSU 1911 Card Game 快速沃尔什变换(FWT)模板题
- 快速沃尔什变换(FWT)讲解 解决集合卷积的方法
- cf 662C Binary Table
- 快速沃尔什变化(FWT)介绍
- 【CODEFORCES】 C. Table Decorations
- 网络基础_传输控制协议/因特网协议1
- hibernate之初学总结(5)
- 文件,,读写copy
- 莫队算法
- 《python初级爬虫》(一)
- Codeforces 662C Binary Table FWT 快速沃尔什变换
- 数组介绍及常用算法的 java 实现
- java -- 泛型简单介绍
- 学习Tango with django(3)
- 51Nod 1090 3个数和为0(O(n^2)复杂度)
- 算法系列(14) Leetcode 492. Construct the Rectangle
- Ubuntu16.04关闭客人会话
- C#——常用的日期时间操作函数
- 线上问题排查:数据库中的一行不能被update