http://poj.org/problem?id=3050

题目大意:

在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始站的位置算一个,能够走回去)

思路:

近期我就是在做水题。。。

直接DFS就可以。。我用map推断序列是否反复的。

#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int pos[10][10];
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
string ans;
int a[10];
map<string ,int>m; void dfs(int x,int y,int cur)
{
if(cur==6)
{
ans.clear();
for(int i=0;i<6;i++)
ans=ans+(char)a[i];
m[ans]++; return;
} for(int i=0;i<4;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||ny<0||nx>4||ny>4)
continue; a[cur]=pos[nx][ny];
dfs(nx,ny,cur+1);
}
} int main()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
scanf("%d",&pos[i][j]); for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
a[0]=pos[i][j];
dfs(i,j,1);
} printf("%d\n",m.size());
return 0;
}

POJ 3050 Hopscotch 水~的更多相关文章

  1. POJ 3050 Hopscotch【DFS带回溯】

    POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...

  2. POJ -3050 Hopscotch

    http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...

  3. 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 ...

  4. poj 3050 Hopscotch DFS+暴力搜索+set容器

    Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...

  5. POJ 3050 Hopscotch 四方向搜索

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6761   Accepted: 4354 Descrip ...

  6. POJ 3050 Hopscotch(dfs,stl)

    用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...

  7. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  8. POJ.1003 Hangover ( 水 )

    POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...

  9. POJ.1552 Doubles(水)

    POJ.1552 Doubles(水) 题意分析 暴力 代码总览 #include <cstdio> #include <stdio.h> #define nmax 100 u ...

随机推荐

  1. VIM中括号的自动补全与删除

    先放来源 http://oldj.net/article/vim-parenthesis/ 很多现代 IDE 都有自动补全配对括号的功能,比如输入了左括号“(”,IDE 就自动在后面添加一个对应的右括 ...

  2. Amazon宣布将MXNet作为AWS的深度学习框架——貌似性能比tf高啊

    Amazon公司的Werner Vogels于上周宣布Amazon深度学习框架将会正式选用MXNet,并且AWS将会通过增加源代码贡献.改进文档以及支持来自其它框架的可视化.开发以及迁移工具,为实现M ...

  3. kafka+storm 单机运行

    环境: 1.kafka+zookeeper 2.window平台 3.eclipse 设置: 1.kafka和zookeeper安装,另一篇有介绍(https://www.cnblogs.com/51 ...

  4. 带中横线的日期格式在iOS手机系统上 转换时间戳NaN问题

    类似于 '2019-04-01 14:13:00' 这样的日期格式转换时间戳在iOS手机上是无法转换的,需要先处理日期格式成 '2019/04/01 14:13:00' var str = '2019 ...

  5. c# 正则表达式regex心得

    5.1. C#中的正则表达式的简介 C#中的Regex类处理正则表达式. 5.2. C#正则表达式的语法 5.3. C#中的正则表达式的特点 下面总结一些C#中的正则表达式相对于其他语言中的正则表达式 ...

  6. window下安装svn

    下载 http://subversion.apache.org/ 注意:上边的黑窗口不要关闭! 如何校验svn服务有运行

  7. 第5章分布式系统模式 使用客户端激活对象通过 .NET Remoting 实现 Broker

    正在 .NET 中构建一个需要使用分布式对象的应用程序,并且分布式对象的生存期由客户端控制.您的要求包括能够按值或按引用来传递对象,无论这些对象驻留在同一台计算 机上,还是驻留在同一个局域网 (LAN ...

  8. Android 使用WindowManager实现Android悬浮窗

    WindowManager介绍 通过Context.getSystemService(Context.WINDOW_SERVICE)可以获得 WindowManager对象. 每一个WindowMan ...

  9. [ Tools ] [ MobaXterm ] [ SSH ] [ Linux ] export and import saved session

    How to export MobaXterm sessions to another computer? https://superuser.com/questions/858973/how-to- ...

  10. 全栈框架——MEAN

    MEAN: MongoDB - Express - AngularJs - Node.js MongoDB 是一个面向文档的. NoSQL 类型的数据库.MongoDB 颠覆了传统的基于表的数据存储方 ...