// 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. 谈谈Linux下动态库查找路径的问题 ldconfig LD_LIBRARY_PATH PKG_CONFIG_PATH

    谈谈Linux下动态库查找路径的问题 ldconfig LD_LIBRARY_PATH  PKG_CONFIG_PATH 转载自:http://blog.chinaunix.net/xmlrpc.ph ...

  2. emoji探寻之路

    emoji是什么? http://www.baike.com/wiki/emoji emoji表情符号,是20世纪90年代由NTT Docomo栗田穣崇(Shigetaka Kurit)创建的,词义来 ...

  3. EBS创建相应的用户

    登陆EBS,依次点击"System Administrator"-->"Security"-->"User"-->&quo ...

  4. 循环编辑文件夹IBMEmptorisSSM-WSDL 下面的所有的wsdl文件到 d盘的wsdlSource下

    @echo off cd C:\Program Files\Java\jdk1.6.0_45\binfor /R "D:\wqcCode\company\emtproj\02 Require ...

  5. Sring控制反转(Inversion of Control,Ioc)也被称为依赖注入(Dependency Injection,DI)原理用反射和代理实现

    首先我有一个数据访问层接口: public interface StudentDao { void save(Student stu); } 和实现类: 1.mysql实现类 public class ...

  6. SpringMVC访问静态资源的三种方式(转)

    本文转自:http://www.iigrowing.cn/springmvc_fang_wen_jing_tai_zi_yuan_de_san_zhong_fang_shi.html 如何你的Disp ...

  7. Application.DoEvents():概念

    When you run a Windows Form, it creates the new form, which then waits for events to handle. Each ti ...

  8. Dynamics AX 2012 R2 从代码中调用SSRS Report

    平时,我们制作SSRS Report的方法主要有两种:使用Query或RDP.如果需要为报表传递参数,就要在代码中为报表参数赋值,然后在代码中调用报表.下面我总结下这两种报表在代码中传参和调用的方式: ...

  9. zigbee学习之路(四):按键控制(中断方式)

    一.前言 通过上次的学习,我们学习了如何用按键控制led,但是在实际应用中,这种查询方式占用了cpu的时间,如果通过中断控制就可以解决这个问题,我们今天就来学习按键控制的中断方式. 二.原理分析 传统 ...

  10. c#链接数据库

    using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; usin ...