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. 设计模式之命令模式(Command)

    #include <iostream> #include <string> using namespace std; class Receiver { public: void ...

  2. Matlab梯度下降解决评分矩阵分解

    for iter = 1:num_iters %梯度下降 用户向量 for i = 1:m %返回有0有1 是逻辑值 ratedIndex1 = R_training(i,:)~=0 ; %U(i,: ...

  3. Leetcode#133 Clone Graph

    原题地址 方法I,DFS 一边遍历一边复制 借助辅助map保存已经复制好了的节点 对于原图中每个节点,如果已经复制过了,直接返回新节点的地址,如果没复制过,则复制并加入map中,接着依次递归复制其兄弟 ...

  4. YEBIS

    在往项目里加yebis做各种后处理 就是看起来很高大上的各种味精 我又热!泪!盈!眶!了 压缩包解开 有各种文档 恩哼~ 大概看了下找到sample build.... 直接就success了.... ...

  5. iOS7 状态栏 修改为白色字体的步骤

    1在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO2 在需要改变状态栏颜色的ViewController中在ViewDidLoad方 ...

  6. SOA之(3)——面向服务计算基础

    面向服务计算基础(Service-Oriented Computing Fundamentals) 面向服务的计算(Service-Oriented Computing) 面向服务的计算是一个伞状术语 ...

  7. 解决iptables和vsftpd设置的问题

    解决iptables和vsftpd设置的问题 博客分类: linux/centos/ubuntu 防火墙J#工作 解决iptables和vsftpd设置的问题 修改 vi /etc/sysconfig ...

  8. 用 VIPER 构建 iOS 应用架构(2)

    [编者按]本篇文章由 Jeff Gilbert 和 Conrad Stoll 共同编写,通过构建一个基础示例应用,深入了解 VIPER,并从视图.交互器等多个部件理清 VIPER 的整体布局及思路.通 ...

  9. Pots of gold game:看谁拿的钱多

    问题描述: Pots of gold game: Two players A & B. There are pots of gold arranged in a line, each cont ...

  10. HDU 1041 Computer Transformation (简单大数)

    Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...