状态压缩+枚举 POJ 3279 Fliptile
/*
题意:问最少翻转几次使得棋子都变白,输出翻转的位置
状态压缩+枚举:和之前UVA_11464差不多,枚举第一行,可以从上一行的状态知道当前是否必须翻转
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int ans[MAXN][MAXN];
int dx[] = {-, , , , };
int dy[] = {, , , -, };
int n, m; int get_col(int x, int y) {
int ret = a[x][y];
for (int i=; i<; ++i) {
int tx = x + dx[i], ty = y + dy[i];
if (tx < || tx >= n || ty < || ty >= m) continue;
ret += b[tx][ty];
}
return ret & ;
} int check(int s) {
memset (b, , sizeof (b));
for (int i=; i<m; ++i) {
if (s & ( << i)) b[][i] = ;
}
for (int i=; i<n; ++i) {
for (int j=; j<m; ++j) {
if (get_col (i-, j)) b[i][j] = ;
}
}
for (int i=; i<m; ++i) if (get_col (n-, i)) return INF;
int ret = ;
for (int i=; i<n; ++i) {
for (int j=; j<m; ++j) ret += b[i][j];
}
return ret;
} int main(void) { //POJ 3279 Fliptile
while (scanf ("%d%d", &n, &m) == ) {
for (int i=; i<n; ++i) {
for (int j=; j<m; ++j) {
scanf ("%d", &a[i][j]);
}
}
int mn = INF;
memset (ans, , sizeof (ans));
for (int i=; i<(<<m); ++i) {
int res = check (i);
if (res < mn) {
mn = res;
for (int i=; i<n; ++i) {
for (int j=; j<m; ++j) {
if (b[i][j]) ans[i][j] = ;
else ans[i][j] = ;
}
}
}
}
if (mn < INF) {
for (int i=; i<n; ++i) {
for (int j=; j<m; ++j) printf ("%d%c", ans[i][j], (j == m-) ? '\n' : ' ');
}
}
else puts ("IMPOSSIBLE");
} return ;
}
状态压缩+枚举 POJ 3279 Fliptile的更多相关文章
- POJ.3279 Fliptile (搜索+二进制枚举+开关问题)
POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...
- POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)
题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...
- POJ 3279 Fliptile(翻格子)
POJ 3279 Fliptile(翻格子) Time Limit: 2000MS Memory Limit: 65536K Description - 题目描述 Farmer John kno ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
- hdu 4033 状态压缩枚举
/* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...
- 状态压缩+枚举 UVA 11464 Even Parity
题目传送门 /* 题意:求最少改变多少个0成1,使得每一个元素四周的和为偶数 状态压缩+枚举:枚举第一行的所有可能(1<<n),下一行完全能够由上一行递推出来,b数组保存该位置需要填什么 ...
- 洛谷P1036 选数 题解 简单搜索/简单状态压缩枚举
题目链接:https://www.luogu.com.cn/problem/P1036 题目描述 已知 \(n\) 个整数 \(x_1,x_2,-,x_n\) ,以及 \(1\) 个整数 \(k(k& ...
- POJ - 3279 Fliptile (枚举)
http://poj.org/problem?id=3279 题意 一个m*n的01矩阵,每次翻转(x,y),那么它上下左右以及本身就会0变1,1变0,问把矩阵变成全0的,最小需要点击多少步,并输出最 ...
随机推荐
- 2018/2/18 SpringCloud Eureka的学习和spirng ribbon的部分源码追踪
昨天对于Eurake大致做了一个介绍,今天就来说说具体怎么配置和使用吧. 首先,我们创建一个服务注册中心 这是它的配置文件 注意,因为我等下还会弄一个Eureka注册中心,所以这里service-ur ...
- VIM使用技巧15
在vim的插入模式下,有时需要插入寄存器中的文本: 1.使用<C-r>{register} 2.使用<C-r><C-p>{register} 3.使用<C-r ...
- Linux下汇编语言学习笔记26 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- 无权二分图最大匹配 HDU2063 匈牙利算法 || Hopcroft-Karp
参考两篇比较好的博客 http://www.renfei.org/blog/bipartite-matching.html http://blog.csdn.net/thundermrbird/art ...
- zoj——3195 Design the city
Design the city Time Limit: 1 Second Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...
- firemonkey获取当前文件所在路径的方法
在之前,我们知道有三种方法: ExtractFilePath(ParamStr(0)) ExtractFilePath(Application.ExeName) GetCurrentDir + '\' ...
- 当遇到Mac的Excel或者Word老是重复崩溃的时候
打开Number,新建文件然后导出为Excel.之后再用Excel打开,一切都OK了.
- zabbix学习系列之基础概念
触发器 概念 "监控项"仅负责收集数据,而通常收集数据的目的还包括在某指标对应的数据超出合理范围时给相关人员发送警告信息,"触发器"正式英语为监控项所收集的数据 ...
- psychology
壹.自身(荣.命) 一.职业分析 ㈠.分析性格→分析长处和短处→分析大家都有的长处→确定自己最终发展的专业. 1 .性格--宗正 耐压力特强,即使肩头责任重大,也能够处理得稳稳当当,是 ...
- [tarjan] 1827 Summer Holiday
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1827 Summer Holiday Time Limit: 10000/1000 MS (Java/ ...