#include <stdio.h>
  #include <set>
  #include <string>
  using namespace std;
 int a[6];
 int b[6];
 int c[100000000];                  //注意是重点,你定义的数字必须的比你的num大,要不会报错的
 int h=0;
  int grid[5][5];    //输入的网格
 int go[4][2] =
{
     0, 1,
     0, -1,
     1, 0,
     -1, 0
 };    //四个方向

 int safe(int y,int x)
{
	int r=1;
	if (x< 0 || x >= 5 || y < 0 || y >= 5)
	{
		r=0;
	}
	return r;
}

 //深度搜索
 void dfs(int row, int col, int step)
 {
     if (step == 6)    //满6个,存到set里
     {
		 int num=0;
		 int flag=1;
       for(int i=0;i<6;i++)
		   b[i]=a[i];

	num=b[0]+b[1]*10+b[2]*100+b[3]*1000+b[4]*10000+b[5]*100000;
	for(int i=0;i<h;i++)
	{
		if(num==c[i])
			flag=0;
	}
	if(flag==0)
		return ;
	if(flag==1)
	{
		c[h++]=num;
	}
	   return ;
     }

     for (int i = 0; i < 4; i++)    //4个方向深度搜索
     {
		  //越界判断
         if (safe(row,col))
		 {
			 a[step]=grid[row][col];
			 int tr = row + go[i][0];
			 int tc = col + go[i][1];
			 dfs(tr, tc, step + 1);
		 }
     }
 }

 int main()
 {
     //输入
     for (int i = 0; i < 5; i++)
         for (int j = 0; j < 5; j++)
             scanf("%d", &grid[i][j]);

     //处理
     for (int i = 0; i < 5; i++)
     {
        for (int j = 0; j < 5; j++)
		{
             dfs(i, j, 0);
         }
    }

	 printf("%d\n",h);
     return 0;
 }

poj3050的更多相关文章

  1. 《挑战程序设计竞赛》2.1 穷竭搜索 POJ2718 POJ3187 POJ3050 AOJ0525

    POJ2718 Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6509   Acce ...

  2. 对比poj3050

    #include <stdio.h> const int MAXN = 10; const int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, ...

  3. POJ3050 Hopscotch 【DFS】

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2113   Accepted: 1514 Descrip ...

  4. 【搜索】POJ-3050 基础DFS

    一.题目 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a ...

  5. POJ3050 -- Hopscotch 简单的dfs搜索

    原题链接:http://poj.org/problem?id=3050 (一些文字过会儿再说现在有事儿) #include <cstdio> #include <set> us ...

  6. POJ-3050

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4385   Accepted: 2924 Descrip ...

  7. poj3050【dfs】

    题意: 5*5的矩阵里,某个点能够上下左右走,走5步,然后路径会形成一个串,问你,这个5*5里面能够形成多少个不同个串. 思路: 直接暴搜,然后对于一个串塞到set里去,然后输出set里的个数就好了 ...

  8. poj3050 Hopscotch

    思路: 水题. 实现: #include <iostream> #include <cstdio> #include <set> using namespace s ...

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

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

随机推荐

  1. mysql查看bin日志命令

    mysqlbinlog --no-defaults   --base64-output=decode-rows -v  --start-datetime='2016-01-14 16:30:00' - ...

  2. mysql中in和exists二者的区别和性能影响

    mysql查询语句in和exists二者的区别和性能影响 还记得一次面试中被人问到in 和 exists的区别,当然只是草草做答,现在来做下分析. mysql中的in语句是把外表和内表作hash 连接 ...

  3. RPM方式安装MySQL5.6和windows下安装mysql解压版

    下载地址: http://cdn.MySQL.com/archives/mysql-5.6/MySQL-server-5.6.13-1.el6.x86_64.rpmhttp://cdn.mysql.c ...

  4. PASCAL==CALLBACK==WINAPI==__stdcall

    VC里面:PASCAL==CALLBACK==WINAPI==__stdcall         _stdcall是Pascal程序的缺省调用方式,通常用于Win32  Api中,函数采用从右到左的压 ...

  5. 便捷的php操作mysql库MysqliDb

    github 地址:https://github.com/joshcam/PHP-MySQLi-Database-Class MysqliDb -- Simple MySQLi wrapper and ...

  6. 自动improt的xcode插件 Auto-Importer

    https://github.com/lucholaf/Auto-Importer-for-Xcode

  7. Bellman-Ford最短路径

    对于前面说到的最短路径的求解方法,不能解决负权边的情况,而Bellman-Ford却可以 共有n个顶点,m条边,每次输入u[i],v[i],w[i],代表从u[i]到v[i]的距离是w[i],对于所有 ...

  8. js javascript jquery区别和联系

    javascript:简称js ,是用于客户端Web开发的一种脚本语言,常用来给HTML网页添加动态功能. jquery:基于JS语言,封装JS的原生方法功能,提供了简便的函数接口,简化了JS的操作. ...

  9. XML操作总结

    在开发过程中对XML的使用不是太多,要用到时候也是想办法绕过去,最近一个同事给了一个详细的操作.分享一下 using System; using System.Collections.Generic; ...

  10. 使用虚幻引擎中的C++导论(三-反射系统与迭代器)

    使用虚幻引擎中的C++导论(三) 第一,这篇是我翻译的虚幻4官网的新手编程教程,原文传送门,有的翻译不太好,但大体意思差不多,请支持我O(∩_∩)O谢谢. 第二,某些细节操作,这篇文章省略了,如果有不 ...