题目链接:http://poj.org/problem?id=3050
Time Limit: 1000MS Memory Limit: 65536K

Description

The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes.

They then adroitly hop onto any digit in the grid and hop forward, backward, right, or left (never diagonally) to another digit in the grid. They hop again (same rules) to a digit (potentially a digit already visited).

With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201).

Determine the count of the number of distinct integers that can be created in this manner.

Input

* Lines 1..5: The grid, five integers per line

Output

* Line 1: The number of distinct integers that can be constructed

Sample Input

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1

Sample Output

15

Hint

OUTPUT DETAILS: 
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be constructed. No other values are possible.

Problem solving report:

Description: 在一个5X5的格子里往四个方向跳,分别为上下左右,可以跳到跳过的数字上,问这样连续的过程能组成多少个不同的六位字符串。
Problem solving: DFS过程中将字符串转换成整数,用set容器保存,最后set的大小即是答案。

Accepted Code:

#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
set <int> spt;
int mp[6][6];
int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void DFS(int x, int y, int s, int l) {if (l >= 6) {spt.insert(s);return ;}for (int i = 0; i < 4; i++) {int tx = x + dir[i][0];int ty = y + dir[i][1];if (tx >= 0 && tx < 5 && ty >= 0 && ty < 5)DFS(tx, ty, s * 10 + mp[tx][ty], l + 1);}
}
int main() {for (int i = 0; i < 5; i++)for (int j = 0; j < 5; j++)scanf("%d", &mp[i][j]);for (int i = 0; i < 5; i++)for (int j = 0; j < 5; j++)DFS(i, j, mp[i][j], 1);printf("%d\n", spt.size());return 0;
}

POJ - Hopscotch(DFS)相关推荐

  1. A - 棋盘问题 POJ - 1321(dfs)

    A - 棋盘问题 POJ - 1321 dfs 复杂度计算: dfs共进行a步,每步需要循环n次,复杂度为 a^n次方 首先是暴力 an*n,果然炸了 #include<cstdio> # ...

  2. poj 2531(dfs)

    题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). 1 #include<iostream> ...

  3. POJ 2458 DFS+判重

    题意: 思路: 搜+判重 嗯搞定 (听说有好多人用7个for写得-.) //By SiriusRen #include <bitset> #include <cstdio>0 ...

  4. POJ 2230 DFS

    题意: Bessie 最近做了农场看守,他每天晚上的工作就是巡视农场并且保证没有坏人破坏农场.从谷仓出发去巡视,并且最终回到谷仓. Bessie 视力不是很好,不能像其他农场的看守一样,对农场的每一条 ...

  5. poj 3411(DFS多点访问)

    题意:有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱,如果没有去过就付R的钱.求的是最少要花多 ...

  6. POJ 3051 DFS

    题意:判断连通块大小 水题 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm ...

  7. poj 3083 DFS

    poj3083 用DFS和BFS.通过这题,我对DFS和BFS再次有了初步的认识!!但是方向问题真的好绕啊..真心没搞懂,还是看了别人的才做出来的.下来我计划再做几道DFS和BFS的题.然后,再去独立 ...

  8. Wang Xifeng's Little Plot (poj 5024 DFS)

    Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj 3256(DFS)

    http://acm.pku.edu.cn/JudgeOnline/problem?id=3256 题意:有k头牛,n个牧场,m条路(每条路相连两个牧场且单向),求全部牛都能到达的牧场有几个. 分析: ...

最新文章

  1. 选择PHP,选择自由与开源
  2. Redis主从握手流程,你真的了解了吗?
  3. Tomcat 下载安装、配置、启动、报错问题
  4. 从最基础的讲起如何做到均匀的生成随机数
  5. 字节输入流_InputStream类FileInputStream类介绍
  6. 漫步最优化二十九——D.S.C.算法
  7. js navigator platform
  8. JavaWeb开发Servlet学习
  9. python在电力系统中的应用_PyPSA在电力系统潮流计算中的应用
  10. 图像处理软件-Adobe Illustrator 2020-位图转化为矢量图
  11. USB Server应用于RPA机器人案例分析
  12. 解读2021年智源 AI 前沿报告:医疗领域最新进展
  13. webservice接口开发经历
  14. 2020测试工具索引
  15. Mac Office 怎么设置单面打印
  16. BERT in tweet_sentiment_extraction
  17. java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY
  18. JavaScript走动的小人
  19. 现如今软件测试还有前景吗?
  20. python简单爬虫入库_python用BeautifulSoup库简单爬虫实例分析

热门文章

  1. python怎么做https请求_Python使用https请求的方法
  2. 【Go语言Web开发框架】Iris快速入门
  3. 利用计算机模拟专家给病人沴,【计算机】模拟部分.ppt
  4. IOS发送通知与接收通知
  5. 2018中国网络安全大会6月在京召开
  6. 关于 tomcat9 下载后启动不了的问题
  7. 【工程数学】笔记3:数字信号处理
  8. ps怎样将图片转为html5,Photoshop中,“点”与“像素”如何相互转换、换算?
  9. Excel VBA:计算BOM*Planning
  10. c 调用 java jni_java JNI 的实现(2)-java和C/C++的相互调用.