// zju 1002
// #include "stdafx.h"
#include <string>
#include <iostream> using namespace std;
int N = 4;
int Max = 0;
char a[5][5];
int judge(int row, int col)//测试该坐标是否可以放置 返回 0 可放置,返回 1 不可放置
{
for (int i = row - 1; i >= 0; i--)//测试该行之前的位置
{
if (a[i][col] == '@')return 1;//不行
if (a[i][col] == 'X')break; }
for (int i = col - 1; i >= 0; i--)
{
if (a[row][i] == '@')return 1;
if (a[row][i] == 'X')break;
}
return 0;
}
void DFS(int pos, int count)
{
int row, col;
if (pos == N*N)
{
if (Max < count)
{
Max = count; return;
}
}
else
{//计算出行列坐标
row = pos / N;
col = pos % N;
//测试该位置是否可行
if (!judge(row, col)&&a[row][col]=='.')
{
a[row][col] = '@';
DFS(pos + 1, count+1);
a[row][col] = '.';//恢复数据
}
DFS(pos + 1, count);//该位置不放置
}
} int main()
{ while (scanf_s("%d",&N)!=EOF&&N)
{
memset(a, 0, sizeof(a));//快速清零
for (int i = 0; i < N; i++)
{ for (int j = 0; j < N; j++)
{
//scanf_s("%c", a[i][j]);
cin >> a[i][j];
}
}
DFS(0, 0);
cout << Max << endl;
Max = 0;
}
return 0;
}

老师还说了一种改良算法,以后有空再写。。。又是只加了几句而已。。。

AC 记得#include <stdio.h>

zju 1002的更多相关文章

  1. [ZJU 1002] Fire Net

    ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we ha ...

  2. ZOJ(ZJU) 1002 Fire Net(深搜)

    Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...

  3. [ZOJ 1002] Fire Net (简单地图搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002 题目大意: 给你一个n*n的地图,地图上的空白部分可以放棋 ...

  4. ZOJ Problem Set - 1002(DFS)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002 题意:给出一个n,有n*n大小的城市,(.)表示空地,从碉堡(O)射 ...

  5. 1002. 写这个号码 (20)(数学啊 ZJU_PAT)

    主题链接:http://pat.zju.edu.cn/contests/pat-b-practise/1002 读入一个自然数n,计算其各位数字之和.用汉语拼音写出和的每一位数字. 输入格式:每一个測 ...

  6. [acm 1002] 浙大 Fire Net

    已转战浙大 题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2 浙大acm 1002 #include <iostre ...

  7. Bestcoder#5 1002

    Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  8. acm 1002 算法设计

    最近突然想往算法方向走走,做了做航电acm的几道题 二话不说,开始 航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长 下面是 ...

  9. BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...

随机推荐

  1. python_os

    1. 基本功能的介绍 os模块包含普通的操作系统的功能 2. 常用的变量 (1)os.name 获取正在使用的平台, Windows 返回 nt, Linux或者Unix 返回 posix 3. 常用 ...

  2. iis 重新注册 .net 方法

    dhl:IIS注册ASP.NET 1.1.2.0.4.0_在win7下如果先安装vs2010 后安装iis7的话,必须注册iis才可以用.~~~!!鄙视微软   IIS中ASP.NET的版本号此时可选 ...

  3. 使用Java字节流拷贝文件

    本文给出使用Java字节流实现文件拷贝的例子 package LearnJava; import java.io.*; public class FileTest { public static vo ...

  4. (转)PHP常用函数

    来源  :http://www.cnblogs.com/dreamhome/archive/2011/05/04/2037011.html ---------------------------- & ...

  5. Unity3D 装备系统学习Inventory Pro 2.1.2 总结

    前言 写在最前面,本文未必适合纯新手,但有一些C#开发经验的还是可以看懂的,虽然本人也是一位Unity3D新人,但是本文只是自己在学习Inventory Pro的学习总结,而不是教程,本人觉得要读懂理 ...

  6. Life is hard

    Life is hard, always so.If there's anything to give you a hard life with sunshine and warmth, please ...

  7. WebApi 接口测试工具:WebApiTestClient

    文章来源:http://www.cnblogs.com/landeanfen/p/5210356.html 一.WebApiTestClient介绍 1.WebApiTestClient组件作用主要有 ...

  8. nodejs框架express准备登录

    目录: 安装模板 静态资源 添加视图 渲染视图 url重定向 模板引擎 从本节课程开始我们要使用express框架实现一个简单的用户登陆功能,让我们先准备一下相关资源. 在nodejs中使用expre ...

  9. 一步一步实现MVC5+EF6+Bootstarp+Autofac+NoSql实现OADemo 之登陆(一) 验证码 Captcha 之大插件小用

    不知何年何月才能完成OADemo啊,总之还是一步一步来吧,这段时间开始着手了,先做登陆.  前段时间研究了一下在CentOS7下安装Mysql和Memcached服务,并测试了用C#操作,结果还行. ...

  10. Safari中的new Date()格式化坑

    今天在测试的时候发现,在Chrome中的如下代码: new Date("2014-03-09"); 在Safari中报错invalid date.经过查阅资料找到类似的问答: st ...