题目链接:http://poj.org/problem?id=3279

题解:http://www.cnblogs.com/helenawang/p/5538547.html

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lp p << 1
#define rp p << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
const int dx[] = {, , , , -};
const int dy[] = {, , -, , };
int G[maxn][maxn];
int tmp[maxn][maxn];
int ret[maxn][maxn];
int n, m, ans; bool ok(int x, int y) {
return x >= && x < m && y >= && y < n;
} int get(int x, int y) {
int c = G[x][y];
Rep(i, ) {
int xx = x + dx[i];
int yy = y + dy[i];
if(ok(xx, yy)) c += tmp[xx][yy];
}
return c % ;
} int calc() {
For(i, , m) Rep(j, n) if(get(i-, j) != ) tmp[i][j] = ;
Rep(i, n) if(get(m-, i) != ) return -;
int p = ;
Rep(i, m) Rep(j, n) p += tmp[i][j];
return p;
} int main() {
// FRead();
while(~Rint(m) && ~Rint(n)) {
Cls(ret); Cls(tmp); Cls(G); ans = -;
Rep(i, m) Rep(j, n) Rint(G[i][j]);
int nn = << n;
Rep(i, nn) {
Cls(tmp);
Rep(j, n) tmp[][n-j-] = i >> j & ;
int num = calc();
if(num >= && (ans < || ans > num)) {
ans = num;
memcpy(ret, tmp, sizeof(tmp));
}
}
if(ans < ) puts("IMPOSSIBLE");
else {
Rep(i, m) {
Rep(j, n) {
printf("%d%c", ret[i][j], j+==n?'\n':' ');
}
}
}
}
RT ;
}

[POJ3279]Fliptile(开关问题,枚举)的更多相关文章

  1. POJ3279 Fliptile 枚举+简单搜索

    题意:一个矩阵,每个点1或0,然后每次翻一个点,它周围上下左右(包括自己)1->0,0->1,问最少翻几次可以矩阵全是0,忽略题目说的字典序 分析:枚举第一行所有的情况,然后下面几行也随之 ...

  2. POJ--3279(开关问题2个不同时间写的代码)

    Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19730   Accepted: 7118 Descrip ...

  3. POJ3279 Fliptile —— 状态压缩 + 模拟

    题目链接:http://poj.org/problem?id=3279 Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  4. POJ3279 Fliptile(暴力)

    有一种暴力是这样的,枚举一边,确定另一边. 这一题是这么解的,枚举第一行所有翻转情况,然后剩下几行其实是确定的,因为前i行翻转方式确定后只能通过第i+1行的翻转来改变第i行的状态,于是依次模拟求出剩下 ...

  5. Fliptile 开关问题 poj 3279

    Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4031   Accepted: 1539 Descript ...

  6. (简单) POJ 3279 Fliptile,集合枚举。

    Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more ...

  7. poj-3279 poj-1753(二进制枚举)

    题目链接:http://poj.org/problem?id=3279 题目大意: 有一个m*n的棋盘(1 ≤ M ≤ 15; 1 ≤ N ≤ 15),每个格子有两面分别是0或1,每次可以对一个格子做 ...

  8. POJ-3279.Fliptile(二进制状态压缩 + dfs) 子集生成

    昨天晚上12点刷到的这个题,一开始一位是BFS,但是一直没有思路.后来推了一下发现只需要依次枚举第一行的所有翻转状态然后再对每个情况的其它田地翻转进行暴力dfs就可以,但是由于二进制压缩学的不是很透, ...

  9. poj3279 Fliptile

    思路: 枚举. 枚举了第一行的操作之后,下面每行的操作也随之确定了.因为在确定了第i行的操作之后,要想再改变a[i][j]的状态只能通过改变a[i + 1][j]来实现.另外,用到了集合的整数表示方法 ...

随机推荐

  1. ActiveMQ使用记录

    1.在Linux中安装ActiveMQ 官方文档地址:http://activemq.apache.org/getting-started.html#GettingStarted-StartingAc ...

  2. thinkphp对数据库操作有哪些内置函数

    getModelName() 获取当前Model的名称 getTableName() 获取当前Model的数据表名称 switchModel(type,vars=array()) 动态切换模型 tab ...

  3. 【CocoaPods】配置CocoaPods前 - 本地安装好Ruby环境

    xcode (反正就是代码编辑器) Xcode就不用说了把. homebrew (反正就是软件管理器) homebrew是一个包管理器,用于在mac上安装一些os x上没有的UNiX工具(比如wget ...

  4. UML 小结(3)- UML的结构及各个阶段的应用

    UML的结构: 其中各个图的作用如下:     用例图:用来描述用户的需求,从用户的角度描述系统的功能,并指出各功能的执行者,强调谁在使用系统,系统为执行者完成哪些功能. 静态图包括类图跟对象图 类图 ...

  5. VS查看工程项目代码行数

    ctrl+shift+F  查找选项选正则表达式  正则表达式 b*[^:b#/]+.*$或 ^b*[^:b#/]+.*$

  6. Team Homework #2

    王宇杰,北航计算机学院2011级本科生,学号11061180.本人没有什么特长,典型的死宅一个.学过一点c和java.对于第一次的个人作业就表示亚历山大,希望各位大神不吝分享自己的代码,并做好注释.希 ...

  7. Oracle 新建序列值

    create sequence MSG_OUTBOX_ID_SEQ minvalue maxvalue start increment cache ;

  8. axure7.0 汉化包下载

    下载地址:http://files.cnblogs.com/files/feijian/axure7.0%E4%B8%AD%E6%96%87%E8%AF%AD%E8%A8%80%E6%B1%89%E5 ...

  9. Jenkins入门-转

    reference : http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html 在网上貌似没有找到Jenkins的中文的太多的文档,有 ...

  10. java递归查询方法

    一.需求 项目里要让用户能够设置所选择教材的章课节,以针对章课节提供相应的题目供用户做题. 设计:用户设置了教材后,首次登录,进行章节设置时.默认为用户选择第一章.第一课.第一节. 思路:用户访问页面 ...