原题链接:http://poj.org/problem?id=3050

(一些文字过会儿再说现在有事儿)

#include <cstdio>
#include <set>
using namespace std;
int a[7][7],dx[]={317,0,0,1,-1},dy[]={318,1,-1,0,0};//4个方向
set<int>ans;//答案
void dfs(int x,int y,int d,int n)//x和y是坐标。d是深度,也就是长度。n是那个搜出来的数
{
if(d==6){ans.insert(n);return;}
int nx,ny;//新的
for(int i=1;i<=4;i++)//4个方向
{
nx=x+dx[i];//计算
ny=y+dy[i];//计算
if(nx>=1&&nx<=5&&ny>=1&&ny<=5)//没出边界
{
dfs(nx,ny,d+1,n*10+a[nx][ny]);//继续搜
}
}
}
int main()
{
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
scanf("%d",&a[i][j]);//输入
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
dfs(i,j,1,a[i][j]);//深搜
printf("%d\n",ans.size());//世界那么大 我想输出答案
return 0;
}

POJ3050 -- Hopscotch 简单的dfs搜索的更多相关文章

  1. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

  2. hihocoder 1050 树中的最长路(动态规划,dfs搜索)

    hihocoder 1050 树中的最长路(动态规划,dfs搜索) Description 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅 ...

  3. poj 3083 Children of the Candy Corn 【条件约束dfs搜索 + bfs搜索】【复习搜索题目一定要看这道题目】

    题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# ...

  4. CodeForces 723D Lakes in Berland (dfs搜索)

    题意:给定一个n*m的矩阵,*表示陆地, . 表示水,一些连通的水且不在边界表示湖,让你填最少的陆地使得图中湖剩下恰好为k. 析:很简单的一个搜索题,搜两次,第一次把每个湖的位置和连通块的数量记下来, ...

  5. hdu 1312:Red and Black(DFS搜索,入门题)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. [ZOJ 1011] NTA (dfs搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...

  7. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  8. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. python--selenium简单模拟百度搜索点击器

    python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...

随机推荐

  1. 配置mysql 问题解决

    问题 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--s ...

  2. maven依赖scope配置项讲解

    我们在使用Maven配置依赖项的时候,常常只会配置Maven的坐标以及版本信息就可以了,但我们看其他人的工程代码的时候常常会见到有个scope配置项,今天就来分别介绍下这个配置下几个类别的作用. &l ...

  3. How to watch property in attrs of directive

    Q: I have a controller that has a counter that changes from time to time. That counter is tied to an ...

  4. C连接oracle数据库

    int db_conn_main() { EXEC SQL BEGEIN DECLARE SECTION; +]; +]; +]; varchar username[]; varchar passwo ...

  5. springMVC 返回json乱码问题

    多次遇见过这个问题,springMVC下返回给前端的json字符串,中文总是乱码,每次都要去翻一下之前的代码来看解决办法,有必要做个笔记记一下这个问题了. 解决方法: 在方法注解中加入如下: @Req ...

  6. 前端学习笔记2017.6.12 CSS控制DIV

    前一篇文章中用div布局了豆瓣东西的页面,如果用html代码表示的话大概是这个样子的 <!DOCTYPE html><html><head></head> ...

  7. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-005Table per subclass with joins(@Inheritance(strategy = InheritanceType.JOINED)、@PrimaryKeyJoinColumn、)

    一.结构 The fourth option is to represent inheritance relationships as SQL foreign key associations. Ev ...

  8. Linux 性能调优

    一.简介 有些时候,我们特别关注程序的性能,特别是底层软件,比如驱动程序,OS等.为了更好的优化程序性能,我们必须找到性能瓶颈点,"好钢用在刀刃上"才能取得好的效果,否则可能白做工 ...

  9. docker卸载与安装

    sudo apt remove docker.io 报错如下: Reading package lists... Done Building dependency tree Reading state ...

  10. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...