[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\ ...
随机推荐
- [转帖]很遗憾,没有一篇文章能讲清楚ZooKeeper
很遗憾,没有一篇文章能讲清楚ZooKeeper https://os.51cto.com/art/201911/606571.htm [51CTO.com原创稿件]互联网时代是信息爆发的时代,信息的高 ...
- Java操作JSON数据(3)--fastjson操作JSON数据
fastjson是阿里巴巴的开源JSON解析库,它可以解析JSON格式的字符串,支持将Java Bean序列化为JSON字符串,也可以从JSON字符串反序列化到JavaBean.本文介绍下fastjs ...
- C语言提高内容目录
(1)基础 数据类型和变量 内存四区(栈 堆 全局 代码区) (2)指针和字符串操作 指针强化 字符串的基本操作 字符串一级指针内存模型图 字符串做为函数参数 (3)二级指针多级指针 二级指针的输入输 ...
- F1 相似查找字段存在的table
REPORT ZME12_BDC1. *REPORT demo_select_dynamic_conditions . TABLES: makt,dd02t,marc. TYPE-POOLS : AB ...
- pytest_skip跳过用例
前言 pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者您希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试. 常见示例是 ...
- Bash速查表
例 #!/usr/bin/env bash NAME="John" echo "Hello $NAME!" 变量 NAME="John" e ...
- java之spring之spring整合hibernate
这篇讲下spring和hibernate的整合 目录结构如下: 1.新建java项目 2.导入jar包 antlr-2.7.7.jar aopalliance.jar aspectjweaver.ja ...
- How to do SSH Tunneling (Port Forwarding)
How to do SSH Tunneling (Port Forwarding) In this post we will see how ssh works?, what is SSH tunne ...
- mysql-数据库查询语句汇总
目录 数据库查询语句 ***** 添加数据补充: 所有的select 关键字 where 条件 distinct 去除重复记录 指定字段 取别名 group by having order limit ...
- 深入理解JVM(三) -- 对象的内存布局和访问定位
一 对象的内存布局: 在HotSpot虚拟机中,对象在内存中存储的布局可以分为3块区域:对象头(Header),实例数据(Instance Data)和对齐填充(Padding). HotSpot的对 ...