poj 1321棋盘问题(搜索)
2015-12-08 19:57
85 查看
题目链接;【poj 1321】
<span style="font-size:14px;">#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <string> using namespace std; char str[10][10]; int row[10], n, col[10]; __int64 ans; void dfs(int x, int k) { if(k==0) { ans++; return; } for(int j=x; j<n; j++) { while(col[j]==0) j++; for(int i=0; i<n; i++) { if(str[i][j]=='#'&&row[i]==0) { row[i]=1; dfs(j+1, k-1); row[i]=0; } } } } int main() { int k, s; while(~scanf("%d%d", &n, &k)) { if(n==-1&&k==-1) break; memset(col, 0, sizeof(col)); memset(row, 0, sizeof(row)); s=0; for(int i=0; i<n; i++) { scanf("%s", str[i]); for(int j=0; j<n; j++) { if(str[i][j]=='#') col[j]=1, s++; } } ans=0; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(str[j][i]=='#') { row[j]=1; dfs(i+1, k-1); row[j]=0; str[j][i]='.'; s--; if(s<k) break; } } if(s<k) break; } printf("%I64d\n", ans); } return 0; }</span>
相关文章推荐
- springMVC+mybatis框架
- iOS和tvOS游戏按需加载资源简介
- Linux rpm 命令参数使用详解[介绍和应用]
- 由hdu2110总结的背包问题
- Activiti进阶(一)——HelloWorld
- 机器学习常见名词
- [LeetCode]101. Trapping Rain Water收集雨水
- hough变换中,直线方程从XY空间转换到参数空间的转换过程
- Android百度云推送实现消息推送
- apply 和 call
- java进阶一之jdk8新特性
- [LeetCode]101. Trapping Rain Water收集雨水
- What is 'lr_policy' in caffe?
- Mecv中遇见的ie兼容问题
- UIResponder
- Android编码规范
- Triangle Count算法
- nltk function
- 栈和队列之LinekedList(双端队列)
- icare3.0运维中数据库使用的注意事项----------运维日志11