【题目大意】

给出一个5*5的方格,求出从任意一点出发走6步组成的不同序列数。

【思路】

dfs的水题,当作set使用方法的初次学习。每次从任意一点出发进行一次dfs,将序列加入set,最后输出set.size()即可。

 #include<iostream>
#include<cstring>
#include<set>
using namespace std;
int map[][];
int dx[]={,,,-};
int dy[]={,-,,};
set<int> s; void dfs(int x,int y,int step,int sum)
{
if (step==)
{
s.insert(sum);
return;
}
for (int i=;i<;i++)
{
int nowx=x+dx[i],nowy=y+dy[i];
if (nowx< || nowy< || nowx>= || nowy>=) continue;
dfs(nowx,nowy,step+,sum*+map[nowx][nowy]);
}
} int main()
{
for (int i=;i<;i++)
for (int j=;j<;j++) scanf("%d",&map[i][j]);
for (int i=;i<;i++)
for (int j=;j<;j++)
dfs(i,j,,map[i][j]);
cout<<s.size()<<endl;
return ;
}

【深搜+set使用学习】POJ3050-Hopscotch的更多相关文章

  1. 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS

    图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...

  2. 【wikioi】1049 棋盘染色(迭代深搜)

    http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...

  3. UVALive 2053 Puzzlestan(深搜+技巧)

    这个题目的深搜形式,我也找出来了,dfs(i,j)表示第i个人选到了第j个物品,但是我却无限RE了,原因是我的viod型深搜太过暴力,我当时定义了一个计数器,来记录并限制递归的层数,发现它已经递归到了 ...

  4. hdu 1026:Ignatius and the Princess I(优先队列 + bfs广搜。ps:广搜AC,深搜超时,求助攻!)

    Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  5. 1016-Prime Ring Problem,素数环,深搜!

    Prime Ring Problem                                                                                   ...

  6. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  7. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  8. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  9. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

随机推荐

  1. js常用模板引擎

    baiduTemplate(百度).artTemplate(腾讯).juicer(淘宝).xtemplate.doT.Jade 1.Handlebars 是 JavaScript 一个语义模板库,通过 ...

  2. TensorFlow中get_variable共享变量调用

    import tensorflow as tf with tf.variable_scope('v_scope',reuse=True) as scope1: Weights1 = tf.get_va ...

  3. mysql not null default / default

    not null default 说明不能是NULL, 并设置默认值 default 设置默认值 , 但值也可能是NULL mysql> create table test (id int, n ...

  4. Java 关于微信公众号支付总结附代码

    很多朋友第一次做微信支付的时候都有蒙,但当你完整的做一次就会发现其实并没有那么难 业务流程和应用场景官网有详细的说明:https://pay.weixin.qq.com/wiki/doc/api/js ...

  5. 【OneNote】使用线性格式输入数学公式

    在OneNote中按Alt+=,就可以开始输入公式. # 对齐公式数组 可以使用@和&来实现,如 \eqarray(x+1&=2@1+2+3+y&=z@3/x&=6)& ...

  6. MACACA===gradle下载和安装

    gradle下载地址: http://services.gradle.org/distributions/ 或者直接点击这个: http://services.gradle.org/distribut ...

  7. shell 智能获取历史记录功能

    vim ~/.inputrc 文件内容: "\e[A": history-search-backward"\e[B": history-search-forwa ...

  8. C基础 多用户分级日志库 sclog

    引言 - sclog 总的设计思路 sclog在之前已经内置到simplec 简易c开发框架中一个日志库. 最近对其重新设计了一下. 减少了对外暴露的接口. 也是C开发中一个轮子. 比较简单, 非常适 ...

  9. servlet为什么要配置web.xml

    (1).为Servlet命名:  <servlet>  <servlet-name>servlet1</servlet-name> <- 这是用于,在serv ...

  10. Valid Number——分情况讨论最经典的题(没细看)——这题必须静下心来好好看看

    Validate if a given string is numeric. Some examples: "0" => true " 0.1 " =&g ...