Hopscotch
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2845   Accepted: 1995

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.
 
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
using namespace std;
int a[][];
int n;
int vis[][];
int dx[]={,,-,},dy[]={-,,,};
set<int> se;
int dfs(int x,int y,int s,int num)
{
if(s==)
{
//cout<<num<<endl;
se.insert(num);
return ;
}
for(int i=;i<;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=&&ny>=&&nx<=&&ny<=&&vis[nx][ny]==)
{
// vis[nx][ny]=1;
dfs(nx,ny,s+,num*+a[nx][ny]);
// vis[nx][ny]=0;
}
}
return ;
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
memset(vis,,sizeof(vis));
for(i=;i<;i++)
for(j=;j<;j++)
scanf("%d",&a[i][j]);
for(i=;i<;i++)
for(j=;j<;j++)
{
//vis[i][j]=1;
dfs(i,j,,a[i][j]);
//vis[i][j]=0;
}
printf("%d\n",se.size());
// set<int>::iterator a=se.begin();
/*for(;a!=se.end();a++)
{
cout<<*a<<endl;
}*/
}

Hopscotch(POJ 3050 DFS)的更多相关文章

  1. Roads in the North(POJ 2631 DFS)

    Description Building and maintaining roads among communities in the far North is an expensive busine ...

  2. 深度搜索DFS-Lake Counting(POJ NO.2386)

    题目链接POJ NO.2386 解题思路: 这个也是一个dfs 的应用,在书上的例子,因为书上的代码并不全,基本都是函数分块来写,通过这个题目也规范了代码,以后能用函数的就都用函数来实现吧.采用深度优 ...

  3. HDU 5416 CRB and Tree(前缀思想+DFS)

    CRB and Tree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  4. [wikioi2144]砝码称重2(另类的dfs)

    题目描述 Description 有n个砝码,现在要称一个质量为m的物体,请问最少需要挑出几个砝码来称? 注意一个砝码最多只能挑一次 输入描述 Input Description 第一行两个整数n和m ...

  5. 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...

  6. 树的判断(poj nyoj hduoj)

    题目: http://ac.jobdu.com/problem.php?pid=1481 http://acm.nyist.net/JudgeOnline/problem.php?pid=129 ht ...

  7. fjwc2019 D1T3 不同的缩写(dinic+trie+dfs)

    #180. 「2019冬令营提高组」不同的缩写 乍看之下没有什么好的方法鸭.......于是考虑暴力. 长度?二分似乎可行. 于是我们二分最长子串的长度(设为$len$),蓝后暴力查找. 先在每个串内 ...

  8. 蓝桥杯之大臣的旅费(两次dfs)

    Description 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市. 为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个 ...

  9. 图的基本算法(BFS和DFS)

    图是一种灵活的数据结构,一般作为一种模型用来定义对象之间的关系或联系.对象由顶点(V)表示,而对象之间的关系或者关联则通过图的边(E)来表示. 图可以分为有向图和无向图,一般用G=(V,E)来表示图. ...

随机推荐

  1. LCD的背光及觸摸屏

    液晶的发现可追溯到19 世纪末,1888 年被奥地利植物学家发现.它是一种在一定温度范围内呈现既不同于固态.液态,又不同于气态的特殊物质态.既具有晶体所具有的各向异性造成的双折射性,又具有液体所特有的 ...

  2. Qt编程之d指针与q指针

    我们在Qt中可以看到两个宏Q_D和Q_Q这两个红分别是取得d指针和q指针的,d指针指向封装的私有类,q指针指向公共的类.(我的理解类似于回调,回指的意思). 为什么Qt要这样实现呢?下面几个链接中的文 ...

  3. 使用OpenSSL生成证书

    使用OpenSSL生成证书 下载安装openssl,进入/bin/下面,执行命令(把ssl目录下的openssl.cnf 拷贝到bin目录下)1.首先要生成服务器端的私钥(key文件):openssl ...

  4. 【转】Java基本数据类型

    原文网址:http://blog.csdn.net/bingduanlbd/article/details/27790287 Java语言是静态类型的(statical typed),也就是说所有变量 ...

  5. 【HDU2795】Billboard(线段树)

    大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1: 可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一 ...

  6. php随机函数

    <?php function generate_password( $length = 6 ) { // 密码字符集,可任意添加你需要的字符 // $chars = 'abcdefghijklm ...

  7. js记录用户行为浏览记录和停留时间(转)

    演示地址:http://weber.pub/demo/160902/test.html 测试源码下载:http://pan.baidu.com/s/1nvPKbSP 密码:r147 解决问题所使用的知 ...

  8. Android应用程序消息处理机制(Looper、Handler)分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6817933 Android应用程序是通过消息来 ...

  9. HTTP协议报文格式

    HTTP协议报文格式 接下来我们看看HTTP协议(Hypertext Transfer Protocol――超文本传输协议)浏览器端(客户端)向WEB服务器端访问页面的过程和HTTP协议报文的格式. ...

  10. Oracle自治事务

    定        义: Autonomous transactions are independent transactions that can be called from within anot ...