标签:== type with mes eof size include amp 规则
Input
Output
Sample Input
2 1
#.
.#
4 4
...#
..#.
.#..
#...
-1 -1
Sample Output
2 1
分析:DFS,搜索完的那列就标记,m表示已经放在棋盘上的棋子数量
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
char a[10][10];
int f[10];
int n,k;
int ans;
int m;
void dfs(int w)
{
if (m==k)
{
ans++;
return ;
}
if (w>=n)
return ;
for (int i=0;i<n;i++)
if (!f[i]&&a[w][i]==‘#‘)
{
f[i]=1;
m++;
dfs(w+1);
f[i]=0;
m--;
}
dfs(w+1);
}
int main()
{
ios::sync_with_stdio(false);
while (cin>>n>>k&&(n!=-1||k!=-1))
{
ans=0;
m=0;
memset(f,0,sizeof(0));
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
cin>>a[i][j];
dfs(0);
cout << ans << endl;
}
return 0;
}
标签:== type with mes eof size include amp 规则
原文地址:http://www.cnblogs.com/lisijie/p/7818585.html