博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF662C Binary Table
阅读量:6963 次
发布时间:2019-06-27

本文共 963 字,大约阅读时间需要 3 分钟。

FWT板子w

就是一个显然的做法就是枚举哪些行翻转,然后对于每一列贪心取翻转或者不翻即min(count(i),n-count(i))

这样肯定是过不去的 我们来考虑优化

我们记录数组F表示对于一个数i它的较优翻转 即上面的那个柿子

然后再记录一个数组表示原来的矩阵中每一列的计数 cnt[i]表示将一列看成一个二进制数 这个数是i的列数

对于答案我们有ans[k] = \sum_{i\otimes j=k}f[i]*cnt[j]就是考虑计算贡献 ans[k]表示行的翻转是k

由于k \otimes j = i是等价于i \otimes j=k的所以我们可以转化成卷积形式然后套上异或FWT即可

【码风日益毒瘤】代码。

//Love and Freedom.#include
#include
#include
#include
#define inf 20021225#define ll long long#define mxn (1<<20)#define int llusing namespace std;int f[mxn+10],cnt[mxn+10];int ans[mxn+10];void fwt(int *a,int n,int f){ for(int k=2,mid=1;k<=n;k<<=1,mid<<=1) { for(int i=0;i
0) a[i+j] = x+y,a[i+mid+j] = x-y; else a[i+j] = (x+y)/2,a[i+mid+j] = (x-y)/2; } }}char ch[100010];int mp[21][100010];int count(int x){ int ct=0; while(x) x=x&(x-1),ct++; return ct;}signed main(){ int n,m; scanf("%lld%lld",&n,&m); for(int i=0;i
>=1; cnt[tmp]++; } int qwq=0,top=1<

 

转载于:https://www.cnblogs.com/hanyuweining/p/10321884.html

你可能感兴趣的文章
python之潜心研究多线程(thread模块) 建议使用threading模块
查看>>
阵列无法解挂导致VCS双机倒换失败
查看>>
ORACLE中用for in 使用cursor
查看>>
Apache - AH00451
查看>>
vim使用技巧
查看>>
nagios+centreon监控构建
查看>>
bootstrap-data-target触发模态弹出窗元素
查看>>
3.第一个MyBatis程序_进化
查看>>
获得ios屏幕上的像素
查看>>
FTPS(下)
查看>>
一个合格的运维工程师应该具有的素质
查看>>
字符串与 集合
查看>>
sort algorithm
查看>>
第 三 十 三 天:shell 编 程 之 监 控 脚 本
查看>>
玩转开放式虚拟格式ovf
查看>>
忘记的五笔输入
查看>>
xgboost 多gpu支持 编译
查看>>
ImportError: No module named extern;
查看>>
bll
查看>>
su身份切换梳理
查看>>