poj 1321
来源:互联网 发布:中国少数民族政策知乎 编辑:程序博客网 时间:2024/05/16 22:21
棋盘问题
深度优先搜索
#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <vector>#include <set>#include <cctype>#include <algorithm>#include <cmath>#include <deque>#include <queue>#include <map>#include <queue>#include <list>#include <iomanip>using namespace std; //////#define INF 0xffffff7#define N 10#define max(a,b)(a>b?a:b)///char board[N][N];int n, k;int cnt;int color[N][N];bool isok(int a, int b){int i, j;for (i = 1; i <= n; i++){if (color[i][b] == 1)return false;}for (i = 1; i <= n; i++){if (color[a][i] == 1)return false;}return true;}void dfs(int cur, int tot){int i, j;if (tot == k){cnt++;return;}if (cur > n )return;//在第cur行放置棋子for (j = 1; j <= n; j++){if (board[cur][j] == '#' && color[cur][j] == 0 && isok(cur, j)){color[cur][j] = 1;dfs(cur + 1, tot + 1);color[cur][j] = 0;}}//如果不放置棋子dfs(cur + 1, tot);}int main(){///int i, j;while (1){cin >> n >> k;if (n == -1 || k == -1)break;for (i = 1; i <= n; i++)for(j = 1; j <= n; j++)cin >> board[i][j];cnt = 0;if (k == 0){cout << 0 << endl;continue;}memset(color, 0, sizeof(color));dfs(1, 0);cout << cnt << endl;}/// return 0;}
- poj 1321
- poj 1321
- poj 1321
- poj 1321
- poj-1321
- poj 1321
- poj 1321
- poj 1321
- poj 1321
- poj 1321
- poj 1321
- POJ 1321
- POJ 1321
- poj --1321
- poj 1321
- poj-1321
- poj 1321
- POJ 1321
- Struts2 工作原理
- [SGU]110. Dungeon
- (转)C++ 虚函数表解析
- Oracle数据库备份与恢复的三种方法
- 小程序求梯形面积
- poj 1321
- 大家一起学C++(1)
- CCActionEase想说爱你也不难
- HDOJ4433-locker,2012ACM天津站C题,DP
- 编辑C程序心得
- Android自定义AlertDialog组件
- overcommit_memory
- 安装ubuntu后需要的配置
- tomcat server.xml Context代码片段简释