poj 1321 棋盘问题(dfs)
来源:互联网 发布:如何设置java环境变量 编辑:程序博客网 时间:2024/05/22 00:09
做动态规划做的伤心了,找点水题找自信。
cur表示当前搜索到哪一行了,book数组用于标记列
#include <iostream>#include <cstring>using namespace std;int n,k,res;int book[10];char Map[10][10];void DFS(int cur, int num){ if(num == k) { ++res; return; } for(int i = cur; i < n; ++i) { for(int j = 0; j < n; ++j) { if(Map[i][j] == '#' && book[j] == 0) { book[j] = 1; DFS(i+1,num+1); book[j] = 0; } } }}int main(){ while(cin >> n >> k && n != -1 && k != -1) { res = 0; memset(book, 0, sizeof(book)); for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) cin >> Map[i][j]; DFS(0,0); cout << res << endl; } return 0;}
0 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)
- Git相关命令及用法
- 何志丹简历
- 防止handler内存泄漏问题
- 通过angular.element,转变成jquery对象,改变样式!
- Android 6.0出现的init: cannot execve(‘XXX’):Permission denied问题:禁止SELINUX的权限设置
- poj 1321 棋盘问题(dfs)
- 运用Floyd算法求得带权有向图任意两点间的最短路径C/C++
- 1008. Elevator (20)
- socket阻塞与非阻塞,同步与异步、I/O模型
- [c++]Leetcode #7 reverse number
- 数据结构===》栈和队列(复习心得)
- UFLDL Exercise:Sparse Autoencoder
- SLAM方法汇总
- 【英语】11月考研英语的愤怒!