Hopscotch(POJ 3050 DFS)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2845 | Accepted: 1995 |
Description
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
Output
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
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)的更多相关文章
- Roads in the North(POJ 2631 DFS)
Description Building and maintaining roads among communities in the far North is an expensive busine ...
- 深度搜索DFS-Lake Counting(POJ NO.2386)
题目链接POJ NO.2386 解题思路: 这个也是一个dfs 的应用,在书上的例子,因为书上的代码并不全,基本都是函数分块来写,通过这个题目也规范了代码,以后能用函数的就都用函数来实现吧.采用深度优 ...
- HDU 5416 CRB and Tree(前缀思想+DFS)
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- [wikioi2144]砝码称重2(另类的dfs)
题目描述 Description 有n个砝码,现在要称一个质量为m的物体,请问最少需要挑出几个砝码来称? 注意一个砝码最多只能挑一次 输入描述 Input Description 第一行两个整数n和m ...
- 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...
- 树的判断(poj nyoj hduoj)
题目: http://ac.jobdu.com/problem.php?pid=1481 http://acm.nyist.net/JudgeOnline/problem.php?pid=129 ht ...
- fjwc2019 D1T3 不同的缩写(dinic+trie+dfs)
#180. 「2019冬令营提高组」不同的缩写 乍看之下没有什么好的方法鸭.......于是考虑暴力. 长度?二分似乎可行. 于是我们二分最长子串的长度(设为$len$),蓝后暴力查找. 先在每个串内 ...
- 蓝桥杯之大臣的旅费(两次dfs)
Description 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市. 为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个 ...
- 图的基本算法(BFS和DFS)
图是一种灵活的数据结构,一般作为一种模型用来定义对象之间的关系或联系.对象由顶点(V)表示,而对象之间的关系或者关联则通过图的边(E)来表示. 图可以分为有向图和无向图,一般用G=(V,E)来表示图. ...
随机推荐
- keil c51中C程序的启动过程
汇编是从org 0000h开始启动,那么keil c51是如何启动main()函数的?keil c51有一个启动程序startup.a51,它总是和c程序一起编译和链接.下面看看它和main()函数是 ...
- keil 中用函数指针调用函数的参数限制
NSIC中,通过函数指针调用的函数的参数的个数没有限制,但是KeilC对此有限制,至多3个参数.因为,KeilC编译时,无法通过函数指针找到该函数的局部数据段,也就无法通过局部数据段传递参数,只能通过 ...
- 《Programming WPF》翻译 第6章 4.应用程序全球化
原文:<Programming WPF>翻译 第6章 4.应用程序全球化 如果你打算发布你的应用程序到全球各地,你可能需要为不同地区的用户界面准备不同的版本.至少,这需要解决将文本翻译成适 ...
- 《Programming WPF》翻译 第5章 8.我们进行到哪里了?
原文:<Programming WPF>翻译 第5章 8.我们进行到哪里了? 样式支持你定义一个策略来设置可视化元素的依赖属性.属性的设置可以被命名以及手动或者编程方式地通过名称应用,或者 ...
- HashMap和Hashtable的差别
1. HashMap 与 Hashtable继承自不同的类 1) HashMap 继承自AbstractMap,而AbstractMap实现了Map接口 2) Hashtable 继承自Dict ...
- ArcGIS Runtime SDK for Android开发之调用GP服务(异步调用)
一.背景说明 通过调用GP服务,Android客户端也能实现专业的.复杂的GIS分析处理功能,从而增加应用的实用价值. ArcGIS Server发布的GP服务,分为同步和异步两种类型,一般执行步骤较 ...
- 获取对象类型(swift)
获取对象类型(swift) by 伍雪颖 let date = NSDate() let name = date.dynamicType println(name) let string = &quo ...
- ASP.NET三层架构的分析
BLL 是业务逻辑层 Business Logic Layer DAL 是数据访问层 Data Access Layer ASP.NET的三层架构(DAL,BLL,UI ...
- 如何在WP8模拟器中连接本地的web服务
这个问题困扰了很久,查找答案一度找偏方向. 其实连接web服务对于wp7不是问题,因为wp7使用的网络就是本机的网络,但是到了wp8模拟器,纯粹的虚拟机,独立的设备,也就有了自己的网络连接,要当做虚拟 ...
- 基础命名空间:序列化 System.Runtime.Serialization
对象通常都有状态(state),从一个对象中抽取这种状态,不论是将它存储于某地,还是通过网络传送,这种抽取动作称为“将一个对象序列化”,而反向处理过程,从一个被序列化的状态重建一个对象即为反序列化. ...