【深搜+set使用学习】POJ3050-Hopscotch
【题目大意】
给出一个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的更多相关文章
- 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS
图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...
- 【wikioi】1049 棋盘染色(迭代深搜)
http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...
- UVALive 2053 Puzzlestan(深搜+技巧)
这个题目的深搜形式,我也找出来了,dfs(i,j)表示第i个人选到了第j个物品,但是我却无限RE了,原因是我的viod型深搜太过暴力,我当时定义了一个计数器,来记录并限制递归的层数,发现它已经递归到了 ...
- 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 ...
- 1016-Prime Ring Problem,素数环,深搜!
Prime Ring Problem ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 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 ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
随机推荐
- httpd -v command not found
使用 find / -name "apachectl"查找文件目录下执行 ./apachectl -v
- win10以前连接过的wifi密码怎么查看
右键点击开始,在菜单中选择打开命令提示符,以管理员的权限打开. 然后输入命令netsh wlan show profile显示以前此电脑连接过的所有WIFI记录配置信息. 确定要查看的WIFI ...
- solaris如何启动ssh服务
先查看一下ssh服务状态:# svcs或# svcs | grep sshonline Aug_07 svc:/network/ssh:default 如需要关闭ssh服务(关闭完可以 svcs | ...
- python基础===抽象
懒惰即美德 斐波那契数列: >>> fibs = [0,1] >>> for i in range(8): fibs.append(fibs[-2]+fibs[-1 ...
- 网络知识===wireshark抓包出现“TCP segment of a reassembled PDU”的解释(载)
网上胡说八道,众说风云,感觉这篇还算靠谱点. 原文链接:http://blog.csdn.net/dog250/article/details/51809566 为什么大家看到这个以后总是会往MSS, ...
- 【LA3882】And then there was one
做sb题也是一种乐趣,是吧…… #include<bits/stdc++.h> #define N 10005 using namespace std; int f[N],m,n,k; i ...
- problems when installed mysql in linux ubuntu
reference:http://www.jb51.net/article/87160.htm?pc 1.ERROR 2002 (HY000): Can't connect to local MySQ ...
- 2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+ ...
- eclipse+opencv
https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html
- JAVA 语言类的特性(成员、重载、构造方法、静态成员)
一.类的私有成员和公有成员 1.私有成员 修饰符private 如果在类的声明前加上修饰符private,则无法从该类的外部访问到该类的内部成员,而只能被该类自身访问和修改,而不嗯那个被其他类, ...