POJ 3050 Hopscotch 四方向搜索
Hopscotch
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6761 | Accepted: 4354 |
Description
They then adroitly hop onto any digit in the grid and hop forward,
backward, right, or left (never diagonally) to another digit in the
grid. They hop again (same rules) to a digit (potentially a digit
already visited).
With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201).
Determine the count of the number of distinct integers that can be created in this manner.
Input
Output
Sample Input
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1
Sample Output
15
Hint
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111,
121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be
constructed. No other values are possible.
题意:给一个5x5的矩阵,从矩阵的任意一个位置开始搜索6次,(允许方向为上下左右四个方向),问一可以产生多少个不同的序列
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
char a[][];
int dir[][]={{,-},{,},{,},{-,}};
set<string>p;
string s; int check(int x,int y)
{
if(x>=&&x<&&y>=&&y<)
return ;
else
return ;
}
void dfs(int x,int y,int n)
{
if(n>=)
{
p.insert(s);
return ;
}
for(int i=;i<;i++)
{
int dx,dy;
dx=x+dir[i][];
dy=y+dir[i][];
if(check(dx,dy)==)
continue;
s=s+a[dx][dy];
dfs(dx,dy,n+);
s.erase(n);
}
return ;
}
int main()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
cin>>a[i][j];
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
s.clear();
dfs(i,j,);
}
}
cout<<p.size()<<endl;
// set<string>::iterator it;
// for(it=p.begin();it!=p.end();it++)
// {
// cout<<*it<<endl;
// }
}
POJ 3050 Hopscotch 四方向搜索的更多相关文章
- poj 3050 Hopscotch DFS+暴力搜索+set容器
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
- POJ 3050 Hopscotch DFS
The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of num ...
- POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- POJ 3126 Prime Path 广度优先搜索 难度:0
http://poj.org/problem?id=3126 搜索的时候注意 1:首位不能有0 2:可以暂时有没有出现在目标数中的数字 #include <cstdio> #include ...
- Hopscotch(POJ 3050 DFS)
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2845 Accepted: 1995 Descrip ...
- 【POJ - 3050】Hopscotch (dfs+回溯)
-->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
随机推荐
- excel 动太生成sql 复制(ctrl+c)即可使用 【即用excel中concatenate函数拼接sql】
如图所示:有test_user表 id(自增).code.name.age.create_time几个字段. 使用函数:=CONCATENATE("insert into test_user ...
- nyoj 34
题目:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=34 思路:第一种方法是枚举10~100进行计算判断,第二种方法是孙子定理,最近正好学了一 ...
- Go语言学习笔记(四)
一.字符串 1.字符串截取 可以使用len(字符串变量)获取字符串的字节长度,其中英文占1个字节长度,中文占用3个字节长度 可以使用变量名[n]获取到字符串第n+1个字节,返回这个字节对应的Unico ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:数据导出与导入
create directory dump_dir as 'd:\dump'; grant read,write on directory dump_dir to scott; --在cmd下 exp ...
- 夯实Java基础(二十二)——Java8新特性之Lambda表达式
1.前言 Java 8于14年发布到现在已经有5年时间了,经过时间的磨练,毫无疑问,Java 8是继Java 5(发布于2004年)之后的又一个非常最重要的版本.因为Java 8里面出现了非常多新的特 ...
- webpack的配置文件[webpack.config.js]
如果项目里没有webpack.config.js这个文件,webpack会使用它本身内置在源码里的配置项. webpack.config.js这个配置名称可以通过指令修改 npx webpack -- ...
- Centos7 更新配置为阿里源步骤
一.yum更换配置源过程 1.备份原有的.repo源文件 首先需要将之前的源进行备份(一般重要的配置文件都需要有备份的意识) # 进入源配置目录 cd /etc/yum.repos.d # 创建备份文 ...
- python关键日期计算
在coding的过程中有时候会需要用到一些特殊日期,比如说是一个月的最后一天的日期,昨天的日期等等. def first_day_of_next_month(self, old_date): old_ ...
- leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字
1.原题: https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Given an array nums of ...
- 编写安全 PHP 应用程序的七个习惯
编写安全 PHP 应用程序的七个习惯 在提及安全性问题时,需要注意,除了实际的平台和操作系统安全性问题之外,您还需要确保编写安全的应用程序.在编写 PHP 应用程序时,请应用下面的七个习惯以确保应 ...