本题解采用二进制枚举的方式
会dfs的大佬欢迎写在评论区里
实在太费解了
请替换***里的内容,好好理解一下代码
#include<iostream>
#include<cmath>
using namespace std;
int a[8][8]={},temp[8][8];
void work(int x,int y){
temp[x][y]***=1;
temp[x+1][y]^=1;
temp[x][y+1]^=1;
temp[x-1][y]^=1;
temp[x][y-1]^=1;
}
bool check(){
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
if(temp[i][j]==0)return ***;
}
}
return 1;
}
int main(){
int t;
cin>>t;
while(t***){
char g[8][8]={};
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
cin>>g[i][j];
a[i][j]=g[i][j]-48;
}
}
int minn=***;
for(int i=***;i<=***;i++){
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
temp[i][j]=a[i][j];
}
}
int zh[15]={},ai=1,tmp=i,cnt=0;
while(tmp!=0){
zh[ai]=tmp%2;
tmp/=2;
ai++;
}
for(int i=5;i>=1;i--){
if(zh[i]==***){
work(1,i);
cnt++;
}
}
for(int j=***;j<=5;j++){
for(int k=1;k<=5;k++){
if(temp[j-1][k]==0){
work(j,k);
cnt++;
}
}
}
if(cnt<minn&&cnt<=6&&check()==1){
minn=cnt;
}
}
if(minn***6){
cout<<"-1\n";
}else{
cout<<minn<<endl;
}
}
return 0;
}