poj 1321 棋盘问题
来源:互联网 发布:软件开发团队建设 编辑:程序博客网 时间:2024/05/02 06:03
深度优先搜索
代码:
#include <iostream>#include <cstring>using namespace std;int n,k;char array[10][10]; //to record the chessboardbool visited[10]; //to record each line's statusint ans ;int sum ;void dfs(int d,int sum){ //d represent the line, sum represent the chess number in the chessboardif(sum == k){ans++;return;}if(d == n+1) return;for(int j=1;j<=n;j++) // start from the dth rowif(!visited[j] && array[d][j] == '#'){visited[j] = true;dfs(d+1,sum+1);visited[j] = false;}dfs(d+1,sum); //start from the (d+1)th row}int main(){while(cin>>n>>k && (n!=-1) && (k!=-1)){ans = 0,sum=0;memset(visited,false,sizeof(visited));for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>array[i][j];dfs(1,0);cout<<ans<<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 棋盘问题
- 有关字符串分割的问题(正则表达式)
- 学习cocos2d-x之路(6)--Tilemap的碰撞检测
- drupal theme 小结
- 极其通熟易懂——字符串匹配的KMP算法
- 百度地图SDK for Android【事件监听】
- poj 1321 棋盘问题
- 代码生成工具原理解析
- 经典线程同步总结 关键段 事件 互斥量 信号量
- 百度地图SDK for Android【覆盖物】
- Android ProgressBar自定义图片进度,自定义渐变色进度条
- C程序设计语言 Exercise 2-9
- 归并排序
- 百度地图SDK for Android【Demo点击屏幕获取地理坐标】
- 安装ttf-mscorefonts-installer的方法