#include <iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 20;
const int inf = 500;
int a[maxn][maxn]={0};
int ans[maxn][maxn];
int step;
int main()
{
int m,n;
cin>>m>>n;
step=inf;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++) cin>>a[i][j];
for(int i=0;i<(1<<n);i++)
{
bool y=true;
int b[maxn][maxn];
int c[maxn][maxn]={0};
memcpy(b,a,sizeof b);
for(int j=0;j<n;j++)
c[0][n-1-j] = (i>>j)&1;
for(int k=1;k<=m;k++)
{
b[k-1][0]=b[k-1][0]^c[k-1][0];
if(n>1)
{
b[k-1][0]=b[k-1][0]^c[k-1][1];
for(int j=1;j<n-1;j++) b[k-1][j]=b[k-1][j]^c[k-1][j]^c[k-1][j-1]^c[k-1][j+1];
b[k-1][n-1]=b[k-1][n-1]^c[k-1][n-1]^c[k-1][n-2];
}
for(int j=0;j<n;j++) b[k][j]=b[k][j]^c[k-1][j];
for(int j=0;j<n;j++) c[k][j]=b[k-1][j];
}
for(int j=0;j<n;j++)
if(b[m-1][j]!=0)
{
y=false;
break;
}
if(y)
{
int tmp=0;
for(int k=0;k<m;k++)
for(int j=0;j<n;j++) tmp+=c[k][j];
if(tmp<step)
{
step=tmp;
memcpy(ans,c,sizeof ans);
}
}
}
if(step!=inf)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n-1;j++) cout<<ans[i][j]<<' ';
cout<<ans[i][n-1]<<endl;
}
}
else cout<<"IMPOSSIBLE\n";
return 0;
}
poj3279
最新推荐文章于 2022-04-01 21:46:18 发布