题目链接:http://poj.org/problem?id=1753
和上一个题一样,将初始状态存成01矩阵,就可以用位运算优化了。黑色白色各来一遍
/*
━━━━━┒ギリギリ♂ 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;
char oho[maxn][maxn]; 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();
n = m = ;
Cls(oho); Cls(ret); Cls(tmp); Cls(G); ans = -;
Rep(i, n) Rs(oho[i]);
Rep(i, m) {
Rep(j, n) {
if(oho[i][j] == 'b') G[i][j] = ;
else 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;
}
Cls(ret); Cls(tmp); Cls(G);
Rep(i, m) {
Rep(j, n) {
if(oho[i][j] == 'b') G[i][j] = ;
else G[i][j] = ;
}
}
Rep(i, nn) {
Cls(tmp);
Rep(j, n) tmp[][n-j-] = i >> j & ;
int num = calc();
if(num >= && (ans < || ans > num)) ans = num;
}
if(ans < ) puts("Impossible");
else printf("%d\n", ans);
RT ;
}