【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 ...
随机推荐
- PySide——Python图形化界面入门教程(四)
PySide——Python图形化界面入门教程(四) ——创建自己的信号槽 ——Creating Your Own Signals and Slots 翻译自:http://pythoncentral ...
- google的开源项目总结(转载)
转自http://www.feng5166.com/blog/424.html google的开源项目值得我们一用的,这些项目很有意义,甚至可以直接用在我们自己的工作上!学习编程的的一个比较好的方式就 ...
- Gradle编译失败 generating the main dex list
编译打包的时候出现这个错误,信息很少. * What went wrong: Execution failed for task ':camCard_Asia_Trunk:transformClass ...
- Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)
源码如下: uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array o ...
- Word Embeddings: Encoding Lexical Semantics
Word Embeddings: Encoding Lexical Semantics Getting Dense Word Embeddings Word Embeddings in Pytorch ...
- 解决手机提示TF卡受损需要格式化问题
昨晚因为上QQ FOR PAD后.关机.结果又杯具了.上次无意看到一个SD卡修复命令,收藏起来了.一试,还真管用.现把它写出来.分享给大家.以后出现SD卡受损,千万不要再格式化内存卡了.修复过程:1. ...
- 详解 Qt 线程间共享数据(使用signal/slot传递数据,线程间传递信号会立刻返回,但也可通过connect改变)
使用共享内存.即使用一个两个线程都能够共享的变量(如全局变量),这样两个线程都能够访问和修改该变量,从而达到共享数据的目的. Qt 线程间共享数据是本文介绍的内容,多的不说,先来啃内容.Qt线程间共享 ...
- ML:吴恩达 机器学习 课程笔记(Week5~6)
Neural Networks: Learning Advice for Applying Machine Learning Machine Learning System Design
- 2015新款 MacBook 用心的测评与试用. 最轻薄的Mac上市
2015新款 MacBook 不一样的测评与试用. 最轻薄的Mac上市了. 直击现场 <HTML开发MacOSApp教程> http://pan.baidu.com/s/1jG1Q58M ...
- Windows Python虚拟环境配置(Distribute + pip + virtualenv + virtualenvwrapper-powershell)
对于Python开发新手,很多人会迷茫那些各种名目的工具和概念,如Python2.7, Python3.3, Distribute, pip, virtualenv,Setuptools, easy_ ...