【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 ...
随机推荐
- MVVMLight 实现指定Frame控件的导航
原文:MVVMLight 实现指定Frame控件的导航 在UWP开发中,利用汉堡菜单实现导航是常见的方法.汉堡菜单导航一般都需要新建一个Frame控件,并对其进行导航,但是在MvvmLight框架默认 ...
- 数据绑定(十一)多路绑定MultiBinding
原文:数据绑定(十一)多路绑定MultiBinding 有时候UI要显示的信息又不止一个数据来源决定,就需要使用MultiBinding,MultiBinding具有一个名为Bindings的属性,其 ...
- rdlc水晶报表在wpf里的使用
1引用程序集 Microsoft.ReportViewer.WinForms 2 xaml 命名空间 xmlns:rv="clr-namespace:Microsoft.Reporting. ...
- 【Linux】查看物理CPU个数、核数、逻辑CPU个数
①物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id) cat /proc/cpuinfo| grep "physical id ...
- WPF svg 转 xmal
原文:WPF svg 转 xmal 今天wpf里面要用矢量图,美工出的是svg格式的,需要将svg格式的转换为xaml 1.第一个尝试是安装Inkscape,这个软件可以直接将svg另存为xaml,但 ...
- win10 uwp 萤火虫效果
原文:win10 uwp 萤火虫效果 本文在Nukepayload2指导下,使用他的思想用C#写出来. 本文告诉大家,如何使用 win2d 做出萤火虫效果. 安装 win2d 安装win2d的方法请使 ...
- myCloudData SDK
http://www.tmssoftware.com/site/myclouddata.asp http://www.tmssoftware.com/site/myclouddatasdk.asp
- 桌面程序阻止Windows关机(使用Message.Result取得DefWindowProc API函数的返回值,非常重要)
Windows Client 客户端在关机,不外乎两种情况: 1. 没有处理 Windows 关机消息: 2.处理了关机消息,但是超时了: 上面这两种情况,都会让Windows 关不了机.在现实生活中 ...
- 怎样让窗口不显示在任务栏和ALT+TAB中(隐藏窗口再嵌套,几乎是万能的办法)
之前想弄个像QQ旋风那样的悬浮窗口,就研究了下怎么让窗口不显示在任务栏中,方法其实很简单就是将窗口的扩张属性设置成WS_EX_TOOLWINDOW,MSDN中对该属性有详细介绍,代码如下: ::Set ...
- Python自动化测试 (八)unittest 单元测试
任何一种编程语言, 都会有单元测试框架, 本文介绍Python 自带的unittest模块 # -* - coding: UTF- -* - class Myclass: def sum(self,x ...