博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu--1045--Fire Net,NYOJ--587--dfs--blockhouses
阅读量:4590 次
发布时间:2019-06-09

本文共 1165 字,大约阅读时间需要 3 分钟。

/*    Name: NYOJ--587--blockhouses    Author: shen_渊     Date: 16/04/17 21:43    Description: dfs,逐个点深度优先搜索,不管能不能放炮台都得继续搜索,能放时考虑放不放 */#include
#include
using namespace std;bool check(int,int);void dfs(int,int);char map[5][5];int n,max_battle;int main(){// freopen("in.txt","r",stdin); ios::sync_with_stdio(false); while(cin>>n,n){ memset(map,0,sizeof(map)); max_battle = 0; for(int i=0; i
>map[i]; dfs(0,0); cout<
<
max_battle)max_battle = ct; return ; } if(map[x][y] == '.' && check(x,y)) { map[x][y] = 'b'; dfs(p+1,ct+1); map[x][y] = '.';// dfs(p+1,ct);错了 如果不能放炮台,还得继续走的 } dfs(p+1,ct);}bool check(int x,int y){ int flag = 1; for(int i=x; i>=0; i--){ if(map[i][y] == 'X')break; if(map[i][y] == 'b'){ flag = 0;break; } } for(int j=y; j>=0; j--){ if(map[x][j] == 'X')break; if(map[x][j] == 'b'){ flag = 0;break; } } return flag;}

 

转载于:https://www.cnblogs.com/evidd/p/7251879.html

你可能感兴趣的文章
unshift()与shift()
查看>>
使用 NPOI 、aspose实现execl模板公式计算
查看>>
行为型模式:中介者模式
查看>>
How to Notify Command to evaluate in mvvmlight
查看>>
STL容器内数据删除
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
{面试题1: 赋值运算符函数}
查看>>
Node中没搞明白require和import,你会被坑的很惨
查看>>
Python 标识符
查看>>
Python mysql 创建连接
查看>>
企业化的性能测试简述---如何设计性能测试方案
查看>>
centos7 安装中文编码
查看>>
POJ - 3683 Priest John's Busiest Day
查看>>
正则表达式start(),end(),group()方法
查看>>
vuejs 学习旅程一
查看>>
javascript Date
查看>>
linux常用命令2
查看>>
狼图腾
查看>>