ACW 95. 费解的开关
递推 1.先枚举第一行的所有可能情况 2.从第二层开始递推 3.check最后一层是否符合条件 时间复杂度 第一层情况数T十字形变换递推次数*
```
#include <bits/stdc++.h>
using namespace std;
const int N =7;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
char g[N][N],bg[N][N];
int dx[5]={-1,0,1,0,0},dy[5]={0,1,0,-1,0};
void turn(int x,int y){
for(int i=0;i<5;i++){
int a=x+dx[i],b=y+dy[i];
if(a>=0&&a<=4&&b>=0&&b<=4)g[a][b]^=1;
}
}
signed main(){
int t;cin>>t;
while(t--){
for(int i=0;i<5;i++){
cin>>bg[i];
}
int ans=10;
for(int i=0;i<32;i++){
int cnt=0;
memcpy(g,bg,sizeof g);
for(int j=0;j<5;j++){
if(i>>j&1){
turn(0,j);
cnt++;
}
}
for(int j=0;j<4;j++){
for(int k=0;k<5;k++){
if(g[j][k]=='0'){
turn(j+1,k);
cnt++;
}
}
}
bool flag=true;
for(int j=0;j<5;j++){
if(g[4][j]=='0')flag=false;
}
if(flag&&ans>cnt)ans=cnt;
}
if(ans>6)ans=-1;
cout<<ans<<Endl;
}
return 0^0;
}
```