题目传送门

 /*
题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(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. macOSX 访问 win7共享文件

    macOSX 访问 win7共享文件 macOSX 访问 win7共享文件 2014年1月8日星期三 开年的第一篇写下自己使用macos中遇到的问题.为后来初学者提供一些浅薄经验. 第一步:WINDO ...

  2. Server Application Unavailable出现的原因及解决方案集锦

    iis ServerAppl 共存 应用程序池 站点  在Asp.net站点中经常出现这种提示 Server Application Unavailable The web application y ...

  3. NGUI 学习笔记实战之二——商城数据绑定(Ndata)

    上次笔记实现了游戏商城的UI界面,没有实现动态数据绑定,所以是远远不够的.今天采用NData来做一个商城. 如果你之前没看过,可以参考上一篇博客   NGUI 学习笔记实战——制作商城UI界面  ht ...

  4. Maya导入Unity的教程

    原地址:http://www.cocoachina.com/gamedev/gameengine/2010/0601/1586.html 昨天已经发布了1Vr.Cn翻译的多维材质模型烘培入Unity  ...

  5. MotionEvent常见值

    常见的动作常量: public static final int ACTION_DOWN        = 0;单点触摸动作 public static final int ACTION_UP     ...

  6. zookeeper 配置详解

    http://blog.csdn.net/shenlan211314/article/details/6185176  因博主原创,所以不能转载 下面是更为详细的配置说明: 前面两篇文章介绍了Zook ...

  7. django静态文件查找逻辑

    最近被django的静态文件配置整疯了. 决定直捣黄龙,看看底层代码: 首先用manage finstatic xxxx.js 看看处理逻辑,发现主要在:C:\Python27\Lib\site-pa ...

  8. CSS用类选择器在本页写样式

    <title>静夜思</title><style type="text/css">p{color:#ff0000; font-size:24px ...

  9. maven web项目build失败

    通过maven build发布web项目到tomcat时报如下异常: [INFO] ---------------------------------------------------------- ...

  10. 传染病控制(codevs 1091)

    题目描述 Description [问题背景] 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国 大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未 ...