#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. IOS开发中的几种设计模式介绍

    ios开发学习中,经常弄不清楚ios的开发模式,今天我们就来进行简单的总结和探讨~ (一)代理模式 应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现. 优势:解耦合 敏捷 ...

  2. java程序打包成jar文件,使用到第三方jar包

    1.右击工程选择Export—>选择JAR file—>选择NEXT,如下图所示 2.选择需要打包的工程,并且选择存放目录,我这放在 E:\jartest 目录下,然后点击NEXT,如下图 ...

  3. bootstrap-列表组

    <div class="container"> <!-- list-group 列表组 给ul添加 list-group-item 列表项 给li添加 --> ...

  4. [IIS]IIS扫盲(七)

    (4)汉化补丁 许多软件都是英文版本的,国人的英语水平普遍不高,包括笔者.因为这个,影响了不少人学习电脑的兴趣. 为了占领市场,软件开发商提供了中文版本:为了大家学习方便,爱好汉化工作的国人制作了汉化 ...

  5. Aquarium Cycling

    http://www.fishyou.com/aquarium-cycling.php Aquarium Cycling Aquarium cycling actually refers to the ...

  6. Bootstrap 4 中 Alerts 实现

    Alert 的使用说明 http://v4-alpha.getbootstrap.com/components/alerts/ JavaScript behavior Triggers Enable ...

  7. javascript MVC(每天有学习一点篇)

    “写的不是代码,是你的思维”,经常觉得自己写的代码“皮粗肉糙”的,看到那些要么精致小巧,要么优雅大方,要么光明磊落的代码时,常常会黯然神伤外加垂涎欲滴. why?(为什么我的代码不能如此..) whe ...

  8. Python从题目中学习:random() module

    最近在给公司培训Python,布置了一道题: ----------------------------------------------------------------------------- ...

  9. C#开发Windows服务 附简单实例实现禁止QQ运行

    本实例主要实现下面三个基本功能 1.C#开发windows服务 2.禁止QQ等程序运行 3.为windows服务创建自动安装程序 下面针对这三个基本功能进行实现 一.C#开发windows服务 Win ...

  10. .Net的Excel 导出 格式设置

    添加引用:Microsoft   Excel   11.0   Object   Library ; 添加:using Microsoft.Office.Interop.Excel; 一.打开Exce ...