[CodeForces 663E] - Binary Table(FWT)
题目
分析
本蒟蒻就不赘述了,就是一个看不出来的异或卷积
精髓在于
mask对sta的影响,显然操作后的结果为mask ^ sta
AC code
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;//必须用long long,过程中可能炸int
const int MAXN = 1<<20;
const LL INF = 1e18;
const int MAXM = 1e5 + 1;
int n, m, num[MAXM];
LL A[MAXN], B[MAXN];
char str[20][MAXM];
inline int calc(int s)
{
int ret = 0;
while(s) ++ret, s -= s&(-s);
return min(n - ret, ret);
}
inline void FWT(LL arr[], const int &len, const int &flg)
{
register LL x, y;
for(register int i = 2; i <= len; i<<=1)
for(register int j = 0; j < len; j += i)
for(register int k = j; k < j + i/2; ++k)
{
x = arr[k], y = arr[k + i/2];
if(~flg) arr[k] = x + y, arr[k + i/2] = x - y;
else arr[k] = (x + y) / 2, arr[k + i/2] = (x - y) / 2;
}
}
int main ()
{
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%s", str[i]);
for(int i = 0; i < m; ++i)
{
for(int j = 0; j < n; ++j)
num[i] |= (str[j][i] - '0') << j;
++A[num[i]];
}
for(int i = 0; i < (1<<n); ++i)
B[i] = calc(i);
FWT(A, 1<<n, 1);
FWT(B, 1<<n, 1);
for(int i = 0; i < (1<<n); ++i)
A[i] *= B[i];
FWT(A, 1<<n, -1);
LL Ans = INF;
for(int i = 0; i < (1<<n); ++i)
Ans = min(Ans, A[i]);
printf("%I64d\n", Ans);
}
[CodeForces 663E] - Binary Table(FWT)的更多相关文章
- [Codeforces]663E Binary Table
某变换好题.不过听说还有O(2^n*n^2)DP的…… Description 给定一个n*m的01矩阵,你可以选择对任意行和任意列取反,使得最终“1”的数量尽量少. Input 第一行两个整数n,m ...
- CodeForces - 662C Binary Table (FWT)
题意:给一个N*M的0-1矩阵,可以进行若干次操作,每次操作将一行或一列的0和1反转,求最后能得到的最少的1的个数. 分析:本题可用FWT求解. 因为其0-1反转的特殊性且\(N\leq20\),将每 ...
- CROC 2016 - Final Round [Private, For Onsite Finalists Only] C. Binary Table FWT
C. Binary Table 题目连接: http://codeforces.com/problemset/problem/662/C Description You are given a tab ...
- Codeforces.662C.Binary Table(状压 FWT)
题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵,你可以选择一些行和一些列并将其中所有的\(01\)反转.求操作后最少剩下多少个\(1\). \(n\le ...
- Codeforces #662C Binary Table
听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...
- CF662C Binary Table FWT
传送门 \(N \leq 20\)很小诶 一个暴力的思路是枚举行的翻转状态然后在列上贪心 复杂度为\(O(2^NM)\)显然过不去 考虑到可能有若干列的初始状态是一样的,那么在任意反转之后他们贪心的策 ...
- 【CF662C】Binary Table(FWT)
[CF662C]Binary Table(FWT) 题面 洛谷 CF 翻译: 有一个\(n*m\)的表格(\(n<=20,m<=10^5\)), 每个表格里面有一个\(0/1\), 每次可 ...
- [CF662C Binary Table][状压+FWT]
CF662C Binary Table 一道 FWT 的板子-比较难想就是了 有一个 \(n\) 行 \(m\) 列的表格,每个元素都是 \(0/1\),每次操作可以选择一行或一列,把 \(0/1\) ...
- CF662C Binary Table【FWT】
CF662C Binary Table 题意: 给出一个\(n\times m\)的\(01\)矩阵,每次可以反转一行或者一列,问经过若干次反转之后,最少有多少个\(1\) \(n\le 20, m\ ...
随机推荐
- asp net core Remote Validation 无法验证
[注意这里,Remote Validation是需要引入Jquery插件和启用客户端验证的]
- Codeforces Round #249 (Div. 2) C. Cardiogram
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Java基础知识点总结(四)
”https://www.runoob.com/java/java-data-structures.html” 成员方法:是类中自己定义的方法. 构造方法:要和自己类中类名相同. 不论是构造函数还是成 ...
- Python 入门(3):运算符
Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 Python算术运算符: + 加 两个对象相加 a + ...
- 2019 快乐阳光java面试笔试题 (含面试题解析)
本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.快乐阳光等公司offer,岗位是Java后端开发,最终选择去了快乐阳光. 面试了很多家公司,感觉大部分公司考察的点 ...
- Weak Session IDs
工具的使用 首先github上下载火狐插件(正版收费),按F12调用 服务器生成sessionID通过response返回给浏览器,sessionID存放在浏览器cookie中,然后再通过cookie ...
- ps 修补工具
最近刚好遇到需要p图去除水印,这里将ps去除水印的使用记录下来已备翻阅 1.需求图片(如下),使用软件 photo shop cc 2017(以下简称ps) 2.操作 2.1方法一 使用五点修复画笔工 ...
- php无限分类方法类
创建数据库以及表 CREATE DATABASE `sortclass`DEFAULT CHARSET utf8; CREATE TABLE IF NOT EXISTS `class` ( `cid` ...
- Flask--配置文件
配置文件 配置文件的方式有很多,下面介绍两种: 第一种:根据全局变量实现 App.py from flask import Flask, session app = Flask(__name__) # ...
- 用cmake构建gtk程序
情况说明 先前已经在windows下基于GDI实现了一个简陋的imshow:基于GDI的imshow:使用stb_image读取图像并修正绘制.考虑跨平台,也考虑万一某天M$不让我们用盗版系统了,还是 ...