poj 1321(dfs,类似八皇后问题)
作者:互联网
#include<iostream> #include<cstring> using namespace std; int n,k,total,m; char ch[10][10]; bool book[10]; void dfs(int cur){ if(m==k){ total++; return; } if(cur>=n){ return; } for(int i=0;i<n;i++){ if(!book[i]&&ch[cur][i]=='#'){ m++; book[i] = true; dfs(cur+1); m--; book[i] = false; } } dfs(cur+1); } int main(){ while(scanf("%d%d",&n,&k)==2&&n!=-1){ for(int i=0;i<n;i++){ scanf("%s",ch[i]); } memset(book,false,sizeof book); total = m = 0; dfs(0); printf("%d\n",total); } return 0; }
标签:10,1321,return,cur,int,dfs,poj,total 来源: https://www.cnblogs.com/stevenzrx/p/15631060.html