【POJ - 3050】Hopscotch (dfs+回溯)
-->Hopscotch
直接写中文了
Descriptions:
他们熟练地跳上其中的一个格子,可以前后左右地跳(不能对角)到另一个格子上。之后继续跳(可能跳到曾经跳过的格子上)。
他们总共跳5次,路径可以看作一个六位数 (准确的说是一个六位序列,如000201是可行的).
请你找到这样的六位序列的总数
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,和 212121 是可行的. 没有其他可行的了
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 10
using namespace std;
int n=;//5*5的地图
int dt[][]= {{,},{-,},{,},{,-}};//4个方向
set<int>number;//存不同的序列
int mp[Maxn][Maxn];//地图
void dfs(int x,int y,int step,int num)//在(x,y)处,序列长度,这个时候的数字
{
if(step==)//序列为6,放入ser容器
{
number.insert(num);
return;
}
for(int i=;i<;i++)//四个方向走路
{
int tx=x+dt[i][];
int ty=y+dt[i][];
if(tx>=&&ty>=&&tx<n&&ty<n)//在地图内
{
step++;
dfs(tx,ty,step,num*+mp[tx][ty]);//更新状态
step--;//回溯
}
}
}
int main()
{
for(int i=;i<n;i++)//输入
for(int j=;j<n;j++)
cin>>mp[i][j];
for(int i=;i<n;i++)//从每一个点开始dfs走5步
for(int j=;j<n;j++)
dfs(i,j,,mp[i][j]);
cout<<number.size()<<endl;
}
【POJ - 3050】Hopscotch (dfs+回溯)的更多相关文章
- poj 3050 Hopscotch DFS+暴力搜索+set容器
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...
- 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 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 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- POJ 3050 枚举+dfs+set判重
思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...
- 【POJ - 3009】Curling 2.0 (dfs+回溯)
-->Curling 2.0 直接上中文 Descriptions: 今年的奥运会之后,在行星mm-21上冰壶越来越受欢迎.但是规则和我们的有点不同.这个游戏是在一个冰游戏板上玩的,上面有一个正 ...
- 素数环(dfs+回溯)
题目描述: 输入正整数n,把整数1,2...n组成一个环,使得相邻两个数和为素数.输出时从整数1开始逆时针排列并且不能重复: 例样输入: 6 例样输出: 1 4 3 2 5 6 1 6 5 2 3 4 ...
随机推荐
- xadmin 无法创建xadmin_log 或者是xadmin源代码使用,没有引用xadmin包报错或 1146, "Table 'mxonline.xadmin_log' doesn't exist"
解决方案: 第一步:将xadmin所在的目录为source_root 第二步:在settings.py中引用xadmin所在的目录 第三步makemigrations和migrate 引起原因:主语是 ...
- Delphi Android ActivityManager(提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管)
ActivityManager: 对Activity交互提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管理,. 这里对Delphi接口进行 ...
- Win8 Metro(C#)数字图像处理--2.62图像对数增强
原文:Win8 Metro(C#)数字图像处理--2.62图像对数增强 [函数名称] 对数增强 WriteableBitmap LogenhanceProcess(Writeabl ...
- js中的scrollTop、offsetTop、clientTop
scrollHeight:获取对象可滚动的高度. scrollWidth:获取对象可滚动的宽度. scrollTop:获取对象最顶端与对象可见区域最顶端的距离. scrollLeft:获取对象左边界与 ...
- Windows实用小工具-问题步骤记录器
今晚给大家介绍个实用的好工具,可以做简单的问题记录,再也不用截图加注释这么辛苦了····· 经测试,这东东在win7,2008 及2008R2里适用,也就是说,在win7以上的系统中才有.好了,下面直 ...
- Android零基础入门第46节:下拉框Spinner
原文:Android零基础入门第46节:下拉框Spinner 上一期学习了GridView的使用,你已经掌握了吗?本期一起来学习Spinner的使用. 一.认识Spinner Spinner其实就是一 ...
- Tobject 类解析
TObject = class //创建 constructor Create; //释放 procedure Free; //初始化实列 class functi ...
- fprintf函数将格式打印到文件,非常好用(怎么没早点发现这个函数)
/* fprintf example */ #include <stdio.h> int main () { FILE * pFile; int n; ]; pFile = fopen ( ...
- Z Order of Controls in Delphi VCL
Get and set the Z Order of controls at runtime in Delphi VCL. If you are looking for a FireMonkey so ...
- Android-小小设置永久解决程序因为未捕获异常而异常终止的问题
(一) 前言各位亲爱的午饭童鞋,是不是经常因为自己的程序中出现未层捕获的异常导致程序异常终止而痛苦不已?嗯,是的.. 但是,大家不要怕,今天给大家分享一个东东可以解决大家这种困扰,吼吼! (二) Un ...