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. 单点登陆CAS安装过程中可能遇到的问题

    可能遇到的问题: 错误: java.security.cert.CertificateException: No name matching localhost found 原因: keystore里 ...

  2. if-else的优化举例

    共有部分: String bookFrom = null; String sheetFrom = null; String bookTo = null; String sheetTo = null; ...

  3. linux下安装vsftp

    1. yum安装vsftp # yum install vsftpd 2. 配置Vsftpd 安装完之后我们要对它进行配置,才能正常使用.编辑vsftpd的配置文件vi /etc/vsftpd/vsf ...

  4. IE如何兼容placeholder属性

    在前端开发中,经常需要为input设置placeholder属性,但是placeholder是HTML5新属性,在IE10以下不兼容,那么如何完美兼容呢? 网上搜索了一下,其实也挺简单的,可以采用以下 ...

  5. jQuery动画流程分析

  6. Firefly卡牌手游《暗黑世界V1.5》服务器端源码+GM管理后台源码

    http://www.9miao.com/content-6-304.html Firefly卡牌手游<暗黑世界V1.5>服务器端源码+GM管理后台源码 关于<暗黑世界V1.5> ...

  7. Google NACL 简介

    Back to README Getting Started This page tells you how to install Native Client and run demos, both ...

  8. 开源搜索引擎Solr的快速搭建及集成到企业门户最佳实施方案--转载

    笔者经过研究查阅solr官方相关资料经过两周的研究实现了毫秒级百万数据的搜索引擎的搭建并引入到企业门户.现将实施心得和步骤分享一下. 1.      jdk1.6 安装jdk1.6到系统默认目录下X: ...

  9. Nutch配置:nutch-default.xml详解

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  10. QTP菜单消失的解决办法

    解决办法一:点击QTP上方菜单栏“Tools” menu->options 项,点击"General" tab, 最后点击“Restore Layout”按钮. 解决办法二: ...