| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我是用递归函数做的,哪位前辈能否指教错在哪?#include <iostream>
using namespace std;
bool a[12][12];int k,b[100][3];
bool inlaw() //判断合法;
{ int i,j;
for(i=1;i<=4;i++)
for(j=1;j<=4;j++)
if(a[i][j])
return 0;
return 1;
}
void swit(int c,int d) //(c,d)处行列取反;
{ int j;
for(j=1;j<=4;j++)
{ a[c][j]=!a[c][j];
a[j][d]=!a[j][d];
}
a[c][d]=!a[c][d];
}
void output()
{ int i;
cout<<k-1<<endl;
for(i=1;i<k;i++)
cout<<b[i][1]<<' '<<b[i][2]<<endl;
}
void DFS(int row,int col)
{ int i,j;
if(inlaw())
output();
else
for(i=row;i<=4;i++)
for(j=col;j<=4;j++)
{ swit(i,j);b[k][1]=i;b[k++][2]=j;
if(i==4&&j==4)
{ if(inlaw())
output();
}
else if(j==4)
DFS(i+1,1);
else
DFS(i,j+1);
swit(i,j);k--;
}
}
int main()
{ char c[12][12];int i,j;
for(i=1;i<=4;i++)
for(j=1;j<=4;j++)
{ cin>>c[i][j];
if(c[i][j]=='+')
a[i][j]=1;
else
a[i][j]=0;
}
k=1;
DFS(1,1);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator