// 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. Android-项目介绍

    一个.net开发人员 在了解android项目只能凭自己的理解慢慢来了! 新建项目 右击 New-JAVA Application Project 傻瓜似的下一步骤填写每一步 文件介绍 Android ...

  2. LuaXMLRPC笔记

    XMLRPC XMLRPC 为以http为传输协议,使用xml格式化数据来执行远程过程调用, 区别于本地过程调用, 即发生在不同主机之间. 属于分布式计算的一种简单实现,比web service简单易 ...

  3. XSS (Cross Site Scripting) Prevention Cheat Sheet(XSS防护检查单)

    本文是 XSS防御检查单的翻译版本 https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sh ...

  4. SecureCRT工具配色方案

    一.配色后的效果图 二.设置背景颜色 1.选项(Options)==>会话选项(Sessions options)==>终端(Terminal)==>仿真(Emulation) 2. ...

  5. shell脚本中切换用户执行相应的命令或者shell脚本的方法

    通常在执行自动化过程中可能需要将root用户切换到其他用户进行执行,如:oralce 但是,执行的命令又要回到root用户下,继续执行root用户下的其他命令. 此时需要了解 su 命令中的参数 -c ...

  6. 使用Redux管理你的React应用

    因为redux和react的版本更新的比较频繁,博客园这里用的redux版本是1.0.1,如果你关心最新版本的使用技巧,欢迎来我的Github查看(https://github.com/matthew ...

  7. APP-SQLAP-10771:Could not reserve record (匹配PO时候)

    ,) SID, substr(C.SERIAL#,,) SERIAL#, substr(B.,) OBJ_NAME, C.STATUS, C.USERNAME, c.action, C.USER#, ...

  8. animation 的属性一共有 6 个值,详细介绍在此

    animation 属性是一个简写属性,用于设置六个动画属性: animation-name animation-duration animation-timing-function animatio ...

  9. Dynamics AX 2012 R2 为运行失败的批处理任务设置预警

    我们主要有两种类型的系统监视:环境健康监视和性能监视. 环境健康监视一般对系统性能影响非常小,是为了提醒潜在的问题. 性能监视通常更有侵入性.监视期间,添加一个负载到环境.因此,它可以回答特定的问题或 ...

  10. 上传预览图片自己做的.md

    1.无插件预览(window.URL.createObjectURL) ```javascript //demo 图片预览  单个 $(".demo input#demo_file" ...