DFS ZOJ 1002/HDOJ 1045 Fire Net
/*
题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(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的更多相关文章
- hdoj 1045 Fire Net
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDU 1045 Fire Net(dfs,跟8皇后问题很相似)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
- HDU 1045 Fire Net 【连通块的压缩 二分图匹配】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- ZOJ 1002:Fire Net(DFS+回溯)
Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we have a square city with s ...
- ZOJ 1002 Fire Net(dfs)
嗯... 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 这道题是想出来则是一道很简单的dfs: 将一 ...
- zoj 1002 Fire Net 碉堡的最大数量【DFS】
题目链接 题目大意: 假设我们有一个正方形的城市,并且街道是直的.城市的地图是n行n列,每一个单元代表一个街道或者一块墙. 碉堡是一个小城堡,有四个开放的射击口.四个方向是面向北.东.南和西.在每一个 ...
随机推荐
- myeclipse2014破解过程
之前装的是10,后来没事试试装了2014,然后再破解2014后发现2010的证书就失效了,之前在网上也没找到方法,这段时间也没管,今天又自己想办法试了试,发现成功了!下边是我在网上找的破解方法的破解步 ...
- 12 day 1
#include <cstdio> int i,j,m,n,t; long long f[6000][6000]; inline int min(int a,int b){ return ...
- Product of Array Exclude Itself
Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WI ...
- operator new3种情况详解
[本文链接] http://www.cnblogs.com/hellogiser/p/operator-new.html [代码] C++ Code 12345678910111213141516 ...
- 2.10 用最少次数寻找数组中的最大值和最小值[find min max of array]
[本文链接] http://www.cnblogs.com/hellogiser/p/find-min-max-of-array.html [题目] 对于一个由N个整数组成的数组,需要比较多少次才能把 ...
- jquery给height拼接动态变量
var sizeLength = "${list.size()}"; if(sizeLength==''){ sizeLength=0; } sizeLength=400*size ...
- css样式,层叠顺序属性z-index
在做项目的时候,居然单击后显示的顺序一直被别的li标签压着,最后终于找到了,是css的z-index属性赋值了,值越大,显示的层就越高 详情推荐百度百科:z-index z-index是针对网页显示中 ...
- HDU1717小数化分数2
小数化分数2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- GPU CUDA 经典入门指南
转自:http://luofl1992.is-programmer.com/posts/38830.html CUDA编程中,习惯称CPU为Host,GPU为Device.编程中最开始接触的东西恐怕是 ...
- How to Optimize Battery Health?
1. click on the battery icon from taskbar next to the date and time. 2. click "More power optio ...