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

给定一个5×5矩阵,问选6个数的不同排列总数是多少!

二维的搜索,注意要判重,数据量很小,直接用map就好。

 #include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std; map<string,int>m;
int f[][],ans;
int dir[][]={-,,,,,,,-}; void dfs(int x,int y,int num,string s)
{
if(num==)
{
if(m[s]==)
{
//cout<<s<<endl;
m[s]++;
ans++;
}
return;
}
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<&&yy>=&&yy<)
{
string str = s;
s+=f[xx][yy]+'';
dfs(xx,yy,num+,s);
s=str; //这里需要回溯
}
}
}
int main()
{
//freopen("a.txt","r",stdin);
for(int i=;i<;i++)
for(int j=;j<;j++) scanf("%d",&f[i][j]);
ans=;
for(int i=;i<;i++)
for(int j=;j<;j++) dfs(i,j,,"");
printf("%d\n",ans);
return ;
}

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的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...

  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. Hopscotch(POJ 3050 DFS)

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Descrip ...

  8. 【POJ - 3050】Hopscotch (dfs+回溯)

    -->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...

  9. POJ 3050:Hopscotch

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2506   Accepted: 1784 Descrip ...

随机推荐

  1. IEEE 802.11 标准列表

    IEEE 802.11 标准列表 IEEE 802.11,1997年,原始标准(2Mbit/s,播在2.4GHz). IEEE 802.11a,1999年,物理层补充(54Mbit/s,播在5GHz) ...

  2. WebServices中Xml的序列化

    一.定义序列化实体类 [System.Xml.Serialization.XmlRoot("Custome_Xml_Root_Name")] //自定义生成的Xml根目录名称 pu ...

  3. 02.Redis主从集群的Sentinel配置

    1.集群环境 1.Linux服务器列表 使用4台CentOS Linux服务器搭建环境,其IP地址如下: 192.168.110.100 192.168.110.101 192.168.110.102 ...

  4. 装载:对CSS中的Position、Float属性的一些深入探讨

    对CSS中的Position.Float属性的一些深入探讨   对CSS中的Position.Float属性的一些深入探讨 对于Position.Float我们在平时使用上可以说是使用频率非常高的两个 ...

  5. W3C和IE中的事件处理函数

    在上一篇文章中提到了关于传统的JS中注册事件对象的一些缺点和问题,下面是关于DOM2级的现代事件绑定.本文中设计到的HTML文件在文章最后 一.W3C事件处理函数 “DOM2 级事件”定义了两个方法, ...

  6. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  7. BZOJ 2653 middle

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=2653 题目大意:多组询问,求左右端点在规定范围内移动所能得到的最大中位数. [分析] 求中 ...

  8. O(V*n)的多重背包问题

    多重背包问题: 有n件物品,第i件价值为wi,质量为vi,有c1件,问,给定容量V,求获得的最大价值. 朴素做法: 视为0,1,2,...,k种物品的分组背包 [每组只能选一个] f[i][j]=Ma ...

  9. 【BZOJ】【2705】【SDOI2012】Longge的问题

    欧拉函数/狄利克雷卷积/积性函数 2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1275  Solv ...

  10. max_flow(Edmond_Karp) 分类: ACM TYPE 2014-09-02 10:47 92人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> usi ...