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的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
随机推荐
- @Override报错
仔细看了下项目 , 是因为有人把project的信息传上来了 , 使用编译的JDK变成了1.5(难道是因为他的1.8的版本我没有 ?) , 右键项目, 选property , 把compiler变成1 ...
- hbase shell 基本命令总结
访问hbase,以及操作hbase,命令不用使用分号hbase shell 进入hbase list 查看表hbase shell -d hbase(main):024:0> scan '.ME ...
- 每天一个Linux命令(3):pwd命令
Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文 ...
- [IIS]IIS扫盲(三)
IIS扫盲贴 --==[精品]==-- IIS扫盲贴 --==[精品]==-- 2000对应iis5.0 xp对应iis5.1 2003对应iis6.0 作者: II ...
- javaSwing文本框组件
public class JTextFieldTest extends JFrame{ private static final long serialVersionUID = 1L; p ...
- QTP实现功能测试的时候,当新版本的页面都改变了,应该如何解决
去更改对象仓库的属性和更改对象仓库.
- Squid服务日志分析
Squid服务日志分析 Apache 和 Squid 是两种著名的代理缓存软件,但Squid 较 Apache 而言是专门的代理缓存服务器软件,其代理缓存的功能强大,支持 HTTP/1.1 协议,其缓 ...
- 【MySQL】InnoDB: Error: checksum mismatch in data file 报错
参考:http://www.jb51.net/article/66951.htm 用5.7版本启动原5.5实例后,再用5.5启动出现以下报错 InnoDB: Error: checksum misma ...
- iptables-qos-tcpcopy-tc-tcpdump
QOS: https://www.chiphell.com/thread-427876-1-1.html iptables指南: http://man.chinaunix.net/network/ip ...
- js 分享到按钮
基础的思路,可以在此基础加强 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...