题目传送门

 /*
题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(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. cocos2d-x创建精灵动画方式汇总

    1.创建精灵框架缓存,并向其中添加相应的动画文件(plist),最后,通过动画集缓存生产动画 CCSpriteFrameCache *cache = CCSpriteFrameCache::share ...

  2. cocos基础教程(7)动作与动画

    动作类(Action) 动作类(Action)是所有动作的基类,它创建的一个对象代表一个动作.动作作用于Node,因此每个动作都需要由Node对象执行.动作类(Action)作为基类,实际上是一个接口 ...

  3. shell截取字符串

    image_tag="pangu-20151021102145\"" 1.用#号截取,符号-右面所有字符串 TMP=${image_tag#*-} echo $TMP 得 ...

  4. http://www.zhihu.com/question/24896283

    http://www.zhihu.com/question/24896283 Rix Tox,太不專業了 三百.知乎用户.raintorr 等人赞同 1. 更改变量名的几种方法这种情况下该如何快速选中 ...

  5. Python DBUtils

    1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...

  6. Java RMI 框架

    RMI(即Remote Method Invoke 远程方法调用).在Java中,只要一个类extends了java.rmi.Remote接口,即可成为存在于服务器端的远程对象,供客户端访问并提供一定 ...

  7. 【转】Eclipse中查看jar包中的源码

    (简单的方式:通过jd-gui来进行反编译,最简单!,参考我的另一篇博文, 地址:http://www.cnblogs.com/gmq-sh/p/4277991.html) Java Decompil ...

  8. linux 学习一:安装jdk和tomcat

    使用secureCRT 一.首先安装centos的rzsz. 1.yum自动安装:(yum安装rzsz) yum install lrzsz 2.手动安装方法如下:(包有问题,还是采用第一种方式) 2 ...

  9. Android涉及到的设计模式

    转载地址:http://blog.csdn.net/dengshengjin2234/article/details/8502097 1.适配器模式:ListView或GridView的Adapter ...

  10. ASP.Net和新对象之context.Server

    描述 Server是一个HttpServerUtility类型的对象,不是一个类名 1.获取服务器上的绝对路径文件名tring ss = context.Server.MapPath("~/ ...