简单搜索step1

POJ-1321

  • 这是第一次博客,题目也很简单,主要是注意格式书写以及常见的快速输入输出和文件输入输出的格式。
  • 递归的时候注意起始是从(-1,-1)开始,然后每次从下一行开始递归。这样vis数组只需要开一维就可以了。
  • 其实这里的递归的c可以不用,因为每次递归都要遍历每一列。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k;
char chess[8][8];
bool vis[8];
int cnt;
void dfs(int r,int c,int ans){
//cout<<r<<" "<<c<<" "<<ans<<endl;
if(ans==k){
cnt++;
return;
}
for(int i=r+1;i<n;i++){
for(int j=0;j<n;j++){
if(!vis[j]&&chess[i][j]=='#'){
vis[j]=1;
dfs(i,j,ans+1);
vis[j]=0;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("E:\vscodes\vscode_c++\C++FileIn.txt","r",stdin);
// freopen("E:\vscodes\vscode_c++\C++FileOut.txt","w",stdout);
while(cin>>n>>k&&(n!=-1&&k!=-1)){
for(int i=0;i<n;i++){
cin>>chess[i];
}
cnt=0;
memset(vis,0,sizeof(vis));
dfs(-1,-1,0);
cout<<cnt<<endl;
}
//system("pause");
return 0;
}

最新文章

  1. python2.7 内置ConfigParser支持Unicode读写
  2. [Erlang 0116] 当我们谈论Erlang Maps时,我们谈论什么 Part 1
  3. Spring框架IOC容器和AOP解析
  4. 批量修改vss工作目录
  5. Verilog学习笔记简单功能实现(六)...............计数分频电路
  6. MongoDB 副本集的原理、搭建、应用
  7. Winform开发框架之字典管理模块的更新,附上最新2013年全国最新县及县以上行政区划代码sql脚本
  8. 【STL】- vector的用法
  9. Autel MaxiDAS DS708 Fatal Application Error illegal operation
  10. 判断checked是否选中
  11. *[topcoder]LCMSetEasy
  12. iframe 刷新
  13. 单台电脑上启动多个Modelsim图形环境窗口的简单办法(windows)
  14. bzoj 1801: [Ahoi2009]chess 中国象棋
  15. python数据类型:序列(字符串,元组,列表,字典)
  16. web全套资料 干货满满 各种文章详解
  17. flume初识
  18. iOS开发之--单个页面禁止右滑返回操作
  19. RESTful Web Service 架构
  20. [Android] Implementation vs API dependency

热门文章

  1. Alternating Strings Gym - 100712D 简单dp &amp;&amp; Alternating Strings II Gym - 100712L 数据结构优化dp
  2. 错误: 未能完成程序集的安装(hr = 0x8007000b)。探测终止。
  3. Python小练习批量爬取下载歌曲
  4. Spring:解决因@Async引起的循环依赖报错
  5. Python——Django框架——Model数据库模型
  6. 自己yy的中缀表达式转后缀表达式(未验证完全正确)
  7. JavaScript 注释规范
  8. TCP 协议三次握手过程分析
  9. git whoami
  10. AirPods 2 声音非常小