1321棋盘

  
// 1321.cpp : 定义控制台应用程序的入口点。
//

#include
" stdafx.h "


#include
< iostream >
using namespace std;
char q[ 10 ][ 10 ];
bool row_used[ 10 ];
int count,num_p;
int k,n;
void DFS( int i)
{
if (num_p == k)
{
count
++ ;
return ;
}
if (i > n)
return ;

for ( int j = 1 ;j <= n;j ++ )
{
if (q[i][j] == ' # ' &&! row_used[j])
{
row_used[j]
= true ;
num_p
++ ;
DFS(i
+ 1 );
row_used[j]
= false ;
num_p
-- ;

}

}
DFS(i
+ 1 ); // i行不放棋子
}
int main()
{
while (cin >> n >> k)
{
count
= 0 ;
num_p
= 0 ;
memset(row_used,
0 , 10 * sizeof (row_used[ 0 ]));
if (n ==- 1 && k ==- 1 )
break ;
for ( int i = 1 ;i <= n;i ++ )
for ( int j = 1 ;j <= n;j ++ )
{
cin
>> q[i][j];
}
DFS(
1 );
cout
<< count << endl;
}
system(
" pause " );
return 0 ;
}

你可能感兴趣的:(1321棋盘)