【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 ...
随机推荐
- WPF滚动条嵌套,响应鼠标滑轮事件的处理
在C# 中,两个ScrollViewer嵌套在一起或者ScrollViewer里面嵌套一个ListBox.Listview(控件本身有scrollviewer)的时候,我们本想要的效果是鼠标滚动整个S ...
- 自定义LISTBOX内子项为checkbox或者radio时,关于IsChecked绑定
IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}&q ...
- linux 用蓝牙和手机通信
加载模块: # modprobe hci_usb # modprobe rfcomm # hciconfig hci0 up # hciconfig hci0 up 查看状况: # hci ...
- iOS开发HTTP协议相关知识总结
HTTP原理 什么是URL URL中常见的几种协议 什么是HTTP协议 HTTP是做什么的 为什么要使用HTTP协议 HTPP协议的通信过程介绍 HTTP请求 HTTP响应 HTTP请求的选择 两种发 ...
- WPF 在一个dll创建一个Window(包含xaml),在另一个dll中再次继承 会出错
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e92390eb-bbfa-42fb-baa9-2286444c0dca/the-comp ...
- C# 查农历 阴历 阳历 公历 节假日
原文:C# 查农历 阴历 阳历 公历 节假日 using System;using System.Collections.Generic;using System.Text; namespace ca ...
- 《译文》借助OCR和神经网络,用JavaScript识别验证码
昨天发现的了一段非常令人惊奇的JavaScript代码,是由ShaunF编写的automatically solves captchas,一个专门应用在Megaupload网站的Greasemonke ...
- nyoj7——街区最短问题
描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间隔相等. 用(x,y)来表示住户坐在的街区. 例如(4,20),表示用户在东西方向第4个街道, ...
- BI-学习之 商业智能项目工具安装
首先咱们先需要下载一个工具,Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2012并安装: 我目前 ...
- 打开并锁定一个文件(使用LockFile API函数)
var aHandle : THandle; aFileSize : Integer; aFileName : String; procedure TForm1.Button3Click(Sender ...