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的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
随机推荐
- ruby 查询mysql方法
首先对需要使用的数据库进行封装,便于使用:数据库表封装源码: mysqlapi.rb #业务涉及的数据库的配置ActiveRecord::Base$db1={:adapter => " ...
- Hibernate getCurrentSession()和openSession()的区别
通过getCurrentSession()创建的Session会绑定到当前线程上:openSession()不会. 通过getCurrentSession()获取Session,首先是从当前上下文中寻 ...
- RabbitMQ介绍6 - 其它
深入话题 Exchange实现路由的方法 http://www.rabbitmq.com/blog/2010/09/14/very-fast-and-scalable-topic-routing-pa ...
- GC之七--gc日志分析工具
性能测试排查定位问题,分析调优过程中,会遇到要分析gc日志,人肉分析gc日志有时比较困难,相关图形化或命令行工具可以有效地帮助辅助分析. Gc日志参数 通过在tomcat启动脚本中添加相关参数生成gc ...
- WCF数据通讯
Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NET Fra ...
- chrome设置可以跨域访问
右键chrome的快捷方式->属性 修改目标属性:添加--args --disable-web-security --user-data-dir=F:\MyChromeDevUserData, ...
- css实现绝对定位元素居中
前端我们时常需要封装一些弹出框,这些弹出框大小都不能确定,多半是用js实现居中. 现在有了css3可以不用js了. .box{ background-color: blueviolet; width: ...
- 黑马程序员_ C语言基础(一)
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------ 开发过程: 编写->编译(只编译源文件,编译成*.o 只会检测语法是否合理,不会检测函数是 ...
- [vB.NET]为控件添加鼠标悬浮时的提示气泡
实例代码: Dim k As ToolTip k = New ToolTip() k.AutoPopDelay = '显示出气泡后的延时时间(毫秒) k.InitialDelay = '出现前的延时( ...
- 关于 presentViewController 时机
类似微信.QQ这些应用如果用户没有登录,会弹出登录界面,如果 presentViewController 是写在 viewDidAppear 之前,会有警告 Presenting view cont ...