dfs-poj-1321棋盘问题
来源:互联网 发布:最好的网络借贷平台 编辑:程序博客网 时间:2024/05/20 12:21
思路:
DFS,注意如果这个行不放,仍然需要搜索,所以需要进一步判断。WA了两发心里苦哇
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;int cow[20];char mp[20][20];int cot=0;int n,m;int ans=0;void dfs(int tx,int rest){ if(rest==0) { ans++; return ; } if(tx==n) return ; for(int i=0;i<n;i++) { if(mp[tx][i]=='#'&&cow[i]==0) { cow[i]=1; dfs(tx+1,rest-1); cow[i]=0; } } if(rest<=n-tx-1) dfs(tx+1,rest);}int main(){ while(~scanf("%d%d",&n,&m)) { if(n==-1&&m==-1) { break; } cot=0; ans=0; memset(cow,0,sizeof(cow)); for(int i=0;i<n;i++) scanf("%s",&mp[i]); dfs(0,m); cout<<ans<<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)
- DFS-POJ-1321-棋盘问题
- POJ 1321--棋盘问题【DFS】
- poj 1321 棋盘问题 (dfs)
- POJ 1321 棋盘问题 dfs
- poj-1321 棋盘问题 DFS
- 计算斐波那契数列的两种常用方式的性能比较
- 微信bug总结一
- PyQt实现的生产者消费者模型
- 颜色空间那些事儿
- [Leetcode] Majority Element
- dfs-poj-1321棋盘问题
- 【洛谷P1268】树的重量 具体问题具体分析
- HDU 5858 Hard problem(计算几何)
- springMVC框架开发笔记 lesson3 SSM框架整合
- HTTP状态码
- [Leetcode] Contains Duplicate
- 判断两个树是否互相镜像
- python(七)下:初识socket网络编程
- 【light-oj】-1006 - Hex-a-bonacci(思维)