poj 1321 棋盘问题(DFS+回溯)
2014-08-19 19:44
239 查看
#include<iostream> #include<cstdio> #include<cstring> char s[10][10]; int cols[10],k,n,ans; void dfs(int a,int t) { int i,j; if(t==k) { ans++; return ; } for(i=a+1;i<n;i++) { for(j=0;j<n;j++) { if(s[i][j]!='.'&&!cols[j])//cols[]不能放同一列 { cols[j]=1; dfs(i,t+1); cols[j]=0;//回溯 } } } } int main() { int i,j; while(scanf("%d%d",&n,&k),n!=-1&&k!=-1) { memset(s,0,sizeof(s)); memset(cols,0,sizeof(cols)); for(i=0;i<n;i++) { scanf("%s",s[i]); } ans=0; dfs(-1,0); printf("%d\n",ans); } return 0; }
相关文章推荐
- poj 1321 棋盘问题 DFS+回溯 回溯学习
- poj 1321 棋盘问题 (dfs 回溯)
- poj 1321 棋盘问题(DFS,回溯)
- POJ 1321 棋盘问题(DFS回溯)
- POJ 1321 棋盘问题 (DFS + 回溯)
- POJ - 1321 棋盘问题(回溯 DFS)
- POJ 1321 棋盘问题 (DFS+回溯)
- POJ - 1321 棋盘问题 (DFS 回溯)
- POJ 1321 棋盘问题(dfs回溯)
- POJ——1321棋盘问题(DFS+回溯)
- POJ-1321 棋盘问题(DFS+回溯)
- poj 1321 棋盘问题(dfs,回溯)
- poj 1321 棋盘问题 dfs 回溯
- POJ 1321棋盘问题(简单搜索dfs回溯)
- POJ 1321 棋盘问题(DFS+回溯)
- POJ 1321----棋盘问题(dfs+回溯)
- poj 1321 棋盘问题 DFS+回溯 回溯学习
- poj 1321 棋盘问题 (DFS )
- poj 1321 棋盘问题 简单DFS
- poj 1321 :棋盘问题 (dfs)