#include <iostream>
using namespace std;
int ans,a[7][7],b[7][7];
int check()
{
int sum=0;
for (int i=1;i<=5;++i)
for (int j=1;j<=5;++j)
b[i][j]=a[i][j];
for (int i=1;i<=4;++i)
for (int j=1;j<=5;++j)
if (b[i][j]==0)
{
b[i][j]=1-b[i][j];
b[i+1][j]=1-b[i+1][j];;
b[i+2][j]=1-b[i+2][j];;
b[i+1][j-1]=1-b[i+1][j-1];;
b[i+1][j+1]=1-b[i+1][j+1];;
sum++;
}
for (int i=1;i<=5;++i)
if (!b[5][i])
return 100;
return sum;
}
void dfs(int dep,int x)
{
if (dep>5)
{
ans=min(ans,x+check());//求最小值
return;
}
a[1][dep]=1-a[1][dep];;//取反
a[1][dep-1]=1-a[1][dep-1];
a[1][dep+1]=1-a[1][dep+1];
a[2][dep]=1-a[2][dep];
dfs(dep+1,x+1);
a[1][dep]=1-a[1][dep];//不取反
a[1][dep-1]=1-a[1][dep-1];
a[1][dep+1]=1-a[1][dep+1];
a[2][dep]=1-a[2][dep];
dfs(dep+1,x);
}
int main()
{
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
char ch;
cin>>ch;
a[i][j]=(int)(ch-'0');
}
}
ans=100;
dfs(1,0);
cout<<ans;
return 0;
}
啊啊啊
最新推荐文章于 2024-05-14 15:57:15 发布