#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高效分页方案及原理

    很久以前的一次面试中,被面试官问到这个问题,由于平时用到的分页方法不多,只从索引.分表.使用子查询精准定位偏移以外,没有使用到其它方法. 后来在看其它博客看到了一些不同的方案,也一直没有整理.今天有时 ...

  2. CRM 2016 级联过滤

    以下以省市为例: function preFilterLookup() { //要进行过滤的lookup按钮加入addPresearch事件 Xrm.Page.getControl("shi ...

  3. angularjs如何在视图渲染结束之后,或者render之后执行指令中的link方法呢?

    angularjs如何在视图渲染结束之后,或者render之后执行指令中的link方法 关键字: $timeout app.directive("myDirective",func ...

  4. [IIS]IIS扫盲(三)

      IIS扫盲贴 --==[精品]==--   IIS扫盲贴     --==[精品]==-- 2000对应iis5.0  xp对应iis5.1  2003对应iis6.0        作者: II ...

  5. apache配置Options详解

    http://www.365mini.com/page/apache-options-directive.htm Options指令是Apache配置文件中一个比较常见也比较重要的指令,Options ...

  6. Java正则表达式详解

    转自http://edu.yesky.com/edupxpt/18/2143018.shtml

  7. HDU5878

    http://acm.hdu.edu.cn/showproblem.php?pid=5878 给出你一个数字,让你求出大于这个数字n并且是形如2^a*3^b*5^c*7^d的最小的数: 就是用打表法求 ...

  8. 全局修改Lable/Button字体

    本次版本需求要把原来的字体全改掉,由于项目中有的是代码创建的,有的是XIB中直接改的,一个一个改工作量太大,使用运行时可以很轻松的实现        首先,项目中大多数设置字体的控件有 Lable, ...

  9. VMware Workstation(虚拟机)v10.0.1 简体中文破解版

    http://www.xp510.com/xiazai/ossoft/desktools/22610.html

  10. c++ primer 5th 练习3.43

    #include <iostream> using namespace std; int main() { ][]={,,,,,,,,,,,}; /* for(int (&i)[4 ...