【深搜+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 ...
随机推荐
- 特征工程(Feature Engineering)
一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...
- 【转】关于Scapy
关于Scapy Scapy的是一个强大的交互式数据包处理程序(使用python编写).它能够伪造 或者解码大量的网络协议数据包,能够发送.捕捉.匹配请求和回复包等等.它可以很容易地处理一些典型操作,比 ...
- Linux Platform驱动模型(二) _驱动方法【转】
转自:http://www.cnblogs.com/xiaojiang1025/archive/2017/02/06/6367910.html 在Linux设备树语法详解和Linux Platform ...
- 算法题之找出数组里第K大的数
问题:找出一个数组里面前K个最大数. 解法一(直接解法): 对数组用快速排序,然后直接挑出第k大的数.这种方法的时间复杂度是O(Nlog(N)).N为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...
- C/C++——[01] 程序的基本框架
我们以HelloWorld这个简单程序为例,该程序在终端打印一行文本: Hello World! 代码如下: #include <stdio.h> int main(){ printf(& ...
- Webstorm和Eclipse常用快捷键
快捷键配置 点击“File”-> “settings” Webstorm预置了其他编辑器的快捷键配置,可以点击 默认配置-Eclipse的常用快捷键对照表 查找/代替 Webstorm快捷键 E ...
- tinyhttpd ------ C 语言实现最简单的 HTTP 服务器
工作流程: 1>服务器启动,在指定端口或随机选取端口绑定httpd服务. 2>收到一个http请求时(其实就是listen端口accept的时候),派生一个线程运行accept_reque ...
- Python Flask 蓝图Blueprint
1. 目录结构 2. manage.py类似于django中manage import fcrm if __name__ == '__main__': fcrm.app.run(port=8001) ...
- Subsets I&&II——经典题
Subsets I Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a s ...
- memcached安装+绑定访问ip
安装: 1.由于memcached是基于libevent的,需要安装libevent,libevent-devel $yum -y install libevent libevent-devel 2. ...