题目传送门

 /*
题意:问最少翻转几次使得棋子都变白,输出翻转的位置
状态压缩+枚举:和之前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的更多相关文章

  1. POJ.3279 Fliptile (搜索+二进制枚举+开关问题)

    POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...

  2. 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 ...

  3. POJ 3279 Fliptile(翻格子)

    POJ 3279 Fliptile(翻格子) Time Limit: 2000MS    Memory Limit: 65536K Description - 题目描述 Farmer John kno ...

  4. codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)

    B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...

  5. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

  6. hdu 4033 状态压缩枚举

    /* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...

  7. 状态压缩+枚举 UVA 11464 Even Parity

    题目传送门 /* 题意:求最少改变多少个0成1,使得每一个元素四周的和为偶数 状态压缩+枚举:枚举第一行的所有可能(1<<n),下一行完全能够由上一行递推出来,b数组保存该位置需要填什么 ...

  8. 洛谷P1036 选数 题解 简单搜索/简单状态压缩枚举

    题目链接:https://www.luogu.com.cn/problem/P1036 题目描述 已知 \(n\) 个整数 \(x_1,x_2,-,x_n\) ,以及 \(1\) 个整数 \(k(k& ...

  9. POJ - 3279 Fliptile (枚举)

    http://poj.org/problem?id=3279 题意 一个m*n的01矩阵,每次翻转(x,y),那么它上下左右以及本身就会0变1,1变0,问把矩阵变成全0的,最小需要点击多少步,并输出最 ...

随机推荐

  1. android中SQLite实现

    SQLite操作类: package com.example.administrator.myapplication; import android.content.Context; import a ...

  2. 类(Class)

    类 · 目的 面向对象的最主要目的是提高程序的重复使用性. · 包括 属性(attribute).方法(method) · 示例 class Bird(object): have_feather = ...

  3. 从零开始写STL—容器—vector

    从0开始写STL-容器-vector vector又称为动态数组,那么动态体现在哪里?vector和一般的数组又有什么区别?vector中各个函数的实现原理是怎样的,我们怎样使用会更高效? 以上内容我 ...

  4. java反射与注解结合使用(根据传入对象输出查询sql)

    我们在项目开发中有很多地方使用到了注解,关于注解的定义与创建小伙伴可以参考我的文章<java注解>.有任何问题的小伙伴们可以在评论区指出哦,欢迎各位大佬指出问题. 今天我要说的是使用注解与 ...

  5. mvn打包源码的方法:maven-source-plugin

    maven-javadoc-plugin可以打包 dubbo-demo-provider-2.6.1-javadoc.jar maven-jar-plugin 打包插件 dubbo-demo-prov ...

  6. mysql: reinit the password

    You can reinit the password : 1.stop mysql /etc/init.d/mysql stop 2.start mysql safe : mysqld_safe - ...

  7. PLSQL Developer来实现不同数据库的表结构以及表数据同步

    PLSQL Developer菜单条中 Tools选项下有Compare User Objects和Compare Table Data功能. 一.Tools --> compare user ...

  8. 使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体server笔记(十)

    第十部分 -- 开发板測试 前几天已经分别将nginx和ffmpeg移植到了开发板上面.可是还是没有进行不论什么的測试并不知道移植后的效果怎样. 今天分别做了两个測试.证明移植的结果是可用的. 1.測 ...

  9. 【codevs2011】【LNOI2013】最小距离之和

    floyed水题 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstr ...

  10. OSS与文件系统的对比

    基本概念介绍_开发指南_对象存储 OSS-阿里云  https://help.aliyun.com/document_detail/31827.html 强一致性 Object 操作在 OSS 上具有 ...