poj3050
#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的更多相关文章
- 《挑战程序设计竞赛》2.1 穷竭搜索 POJ2718 POJ3187 POJ3050 AOJ0525
POJ2718 Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6509 Acce ...
- 对比poj3050
#include <stdio.h> const int MAXN = 10; const int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, ...
- POJ3050 Hopscotch 【DFS】
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2113 Accepted: 1514 Descrip ...
- 【搜索】POJ-3050 基础DFS
一.题目 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a ...
- POJ3050 -- Hopscotch 简单的dfs搜索
原题链接:http://poj.org/problem?id=3050 (一些文字过会儿再说现在有事儿) #include <cstdio> #include <set> us ...
- POJ-3050
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4385 Accepted: 2924 Descrip ...
- poj3050【dfs】
题意: 5*5的矩阵里,某个点能够上下左右走,走5步,然后路径会形成一个串,问你,这个5*5里面能够形成多少个不同个串. 思路: 直接暴搜,然后对于一个串塞到set里去,然后输出set里的个数就好了 ...
- poj3050 Hopscotch
思路: 水题. 实现: #include <iostream> #include <cstdio> #include <set> using namespace s ...
- 【POJ - 3050】Hopscotch (dfs+回溯)
-->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
随机推荐
- Java事务处理全解析(五)—— Template模式
在本系列的上一篇文章中,我们讲到了使用TransactionManger和ConnectionHolder完成线程安全的事务管理,在本篇中,我们将在此基础上引入Template模式进行事务管理. Te ...
- HDU 4135 Co-prime(容斥原理)
Co-prime 第一发容斥,感觉挺有意思的 →_→ [题目链接]Co-prime [题目类型]容斥 &题意: 求(a,b)区间内,与n互质的数的个数. \(a,b\leq 10^{15}\) ...
- web.xml 文件配置01
web.xml 文件配置01 前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...
- android studio This client is too old to work with the working copy at
http://www.cnblogs.com/maijin/archive/2013/01/09/2852330.html http://stackoverflow.com/questions/283 ...
- 预处理语句--#define、#error和#warning
1.#define语句 我们经常会这样定义一些宏: #define BLOCK 8192 但这样的宏却不能在字符串中展开,如: printf("The BLOCK numb ...
- 如何修改SharePoint列表条数等阈值
若要修改SharePoint中对列表最大条数等设定的阈值,可按如下步骤操作: 1. 打开页面:管理中心 > 应用程序管理 > 管理Web应用程序.2. 选择要修改阈值的Web应用程序,并在 ...
- .NET使用一般处理程序生成验证码
运行的效果图: HTML的代码: <head> <script type="text/javascript"> function changeCode() ...
- ACM好书推荐
年末感想之(渣渣的我) 仔细想想,搞比赛的日子4年有余了,确实不服老不行了,直到现在平均每天的题量都在3题左右.其实真想说,“渣渣的我”.做的题确实不少了,但是水平还是上不了档次. ...
- 【练习】flushback基于时间的闪回查询
1.创建table t1 :: SCOTT@ORA11GR2>create table t1 as select * from scott.emp; Table created. :: SCOT ...
- dp4
T1.机器分配(machine) 题目大意:把N台机器分给M个公司,每个公司分到不同数量机器有不同利润,求分配的最大利润. N<=100,M<=100 解题思路:一眼题啊.设a[x][y] ...