#include <iostream>
#include <limits.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <queue>
using namespace std;
int a[17][17];
int b[17][17];
int c[17][17];
int ans[17][17];
void change(int i, int j) {
if(b[i][j] == 1)
b[i][j] = 0;
else b[i][j] = 1;
}
void manage(int i, int j) {
change(i,j);
change(i-1,j);
change(i,j-1);
change(i+1,j);
change(i,j+1);
c[i][j] = 1;
}
int main() {
int m,n;
cin >> m;
cin >> n;
int max = 1;
for(int i = 1; i <= m; ++i)
for(int j = 1; j <= n; ++j)
scanf("%d", &a[i][j]);
for(int i = 0; i < n; ++i)
max *= 2;
int t = 300;
for(int i = 0; i < max; ++i) {
memset(c, 0, sizeof(c));
int count = 0;
for(int i = 1; i <= m; ++i)
for(int j = 1; j <= n; ++j)
b[i][j] = a[i][j];
int cnt = 1;
int tt = i;
while(tt >= 1) {
if((tt & 1) == 1) {
manage(1,cnt);
count++;
}
tt = tt >> 1;
}
int flag = 0;
for(int i = 2; i <= m; ++i)
for(int j = 1; j <= n; ++j) {
if(b[i-1][j] == 1) {
manage(i,j);
count++;
}
}
for(int j = 1; j <= n; ++j)
if(b[m][j] == 1)
flag = 1;
if(t > count && flag == 0) {
t = count;
for(int i = 1; i <= m; ++i)
for(int j = 1; j <= n; ++j)
ans[i][j] = c[i][j];
}
}
if(t == 300)
cout << "IMPOSSIBLE" << endl;
else for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}
20190908_poj3279
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...