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. c++迭代器失效问题

    参考两篇文章:https://blog.csdn.net/skyroben/article/details/70877008 https://lichanghao.github.io/2016/08/ ...

  2. Razor Intro

    http://www.w3schools.com/aspnet/razor_intro.asp Razor is not a programming language. It's a server s ...

  3. CodeForces 651C

    Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg s ...

  4. 48.自用qss

    /* R1 */ QDialog { background-image: url(:/images/background.png); } /* R2 */ QLabel { font: 9pt; co ...

  5. 文档控件NTKO OFFICE 详细使用说明之预览word编辑保存回服务器

    1.在线预览Word文件 (1) 运行环境 ① 浏览器:支持IE7-IE11(平台版本还支持Chrome和Firefox) ② IE工具栏-Internet 选项:将www.ntko.com加入到浏览 ...

  6. 第4章 部署模式 Three-Tiered Distribution(三级分布)

    影响因素 Tiered Distribution 中讨论的影响因素也适用于此模式.有关这些通用影响因素的讨论,请参阅"Tiered Distribution".下列影响因素仅适用于 ...

  7. Android Toolbar使用及Fragment中的Toolbar处理

    Toolbar作为ActionBar使用介绍 本文介绍了在Android中将Toolbar作为ActionBar使用的方法.并且介绍了在Fragment和嵌套Fragment中使用Toolbar作为A ...

  8. Struts2框架学习(二)——访问流程及架构

    1.Struts2的执行流程 从客户端发送请求过来,先经过前端控制器(核心过滤器StrutsPrepareAndExecuteFilter)过滤器中执行一组拦截器(一组拦截器就会完成部分功能代码),拦 ...

  9. JVM内存划分以及值传递和引用传递的区别

    Day05_SHJavaTraing_4-8-2017 一.JVM对自己的内存划分为5个区域    1.方法栈:所有的方法运行的时候进入内存    2.堆:存储的是容器和对象    3.方法和数据共享 ...

  10. UVa10082 没有通过

    #include<stdio.h> char s[]={"`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"},b[100 ...