题目传送门

 /*
题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台
搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1)左下角走,x = cnt / n; y = cnt % n; 更新坐标,
直到所有点走完为止,因为从左边走到右边,只要判断当前点左上方是否满足条件就可以了
注意:当前点不能放炮台的情况也要考虑
g[x][y] == 'o'; 的错误半天才检查出来:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
char g[][];
int ans;
int n; bool ok(int x, int y)
{
for (int i=y-; i>=; --i)
{
if (g[x][i] == 'o') return false;
else if (g[x][i] == 'X') break;
}
for (int i=x-; i>=; --i)
{
if (g[i][y] == 'o') return false;
else if (g[i][y] == 'X') break;
} return true;
} void DFS(int cnt, int tot)
{
if (cnt == n * n)
{
if (ans < tot) ans = tot;
return ;
} else
{
int x = cnt / n;
int y = cnt % n; if (g[x][y] == '.' && ok (x, y) == true)
{
g[x][y] = 'o';
DFS (cnt+, tot+);
g[x][y] = '.';
} DFS (cnt+, tot);
}
} int main(void) //ZOJ 1002/HDOJ 1045 Fire Net
{
//freopen ("ZOJ_1002.in", "r", stdin); while (scanf ("%d", &n) == && n)
{
for (int i=; i<n; ++i)
scanf ("%s", &g[i]); ans = -; DFS (, ); printf ("%d\n", ans);
} return ;
} /*
5
1
5
2
4
*/

DFS ZOJ 1002/HDOJ 1045 Fire Net的更多相关文章

  1. hdoj 1045 Fire Net

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  3. HDU 1045 Fire Net(dfs,跟8皇后问题很相似)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)   ...

  4. hdu 1045 Fire Net(最小覆盖点+构图(缩点))

    http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB   ...

  5. HDU 1045 Fire Net 【连通块的压缩 二分图匹配】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)    ...

  6. HDU 1045 Fire Net 状压暴力

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  7. ZOJ 1002:Fire Net(DFS+回溯)

    Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we have a square city with s ...

  8. ZOJ 1002 Fire Net(dfs)

    嗯... 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 这道题是想出来则是一道很简单的dfs: 将一 ...

  9. zoj 1002 Fire Net 碉堡的最大数量【DFS】

    题目链接 题目大意: 假设我们有一个正方形的城市,并且街道是直的.城市的地图是n行n列,每一个单元代表一个街道或者一块墙. 碉堡是一个小城堡,有四个开放的射击口.四个方向是面向北.东.南和西.在每一个 ...

随机推荐

  1. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  2. xocde真机测试 内存查看

    如上, 有的时候真机调试, 内存和cpu占用没有被展示出来, 那么真机测试的时候怎么查看我们当前使用的内存呢, 有办法: instrument->activity monitory 点击左上角的 ...

  3. 鸟哥的linux私房菜学习笔记 __ 命令与文件的搜寻

    连续输入两次[tab]按键就能够知道使用者有多少命令可以下达.那你知不知道这些命令的完整档名放在哪里?举例来说,ls 这个常用的命令放在哪里呢? 就透过 which 或 type 来找寻吧! 范例一: ...

  4. 自动化运维之puppet的学习(如何找到你需要的模块)

    https://forge.puppetlabs.com/  puppet 模块下载 http://kisspuppet.com/2014/01/14/puppet_forge_modules/ pu ...

  5. NGINX userid 分析、解码

    NGINX userid 分析.解码 生成userid的代码在 http/modules/ngx_http_userid_filter_module.c 大概550行左右. uid_set 是4个ui ...

  6. 字符编码浅识:关于Unicode与UTF-8

    参考自阮一峰博客:http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html Unicode只是一个符号集,它只规定了符号的 ...

  7. iOS 关于objectForKey返回类型是不是mutable

    以前看NSUserDefault时,记住了那里的objectForKey返回的一定是immutable的对象.现在有点弄混了,其实,NSObject的objectForKey方法没有这个限制,是可以返 ...

  8. Java for LeetCode 043 Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. CodeForces - 426A(排序)

    Sereja and Mugs Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  10. c++流的读写

    std::istream input_stream;//这是一个文件流,想把它写入文件 思路是,先将input_stream流读入一个char* buffer; 然后用std::ofstream将bu ...