poj 3050 Hopscotch DFS+暴力搜索+set容器
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2774 | Accepted: 1940 |
Description
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
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<cstdio>
#include<set>
#include<cstring>
using namespace std;
int a[7][7];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
set<int> q;
int dfs(int step,int x,int y,int v)
{
if(step==6)
q.insert(v);
else
for(int i=0;i<=3;i++)
{
int kx=x+dx[i];
int ky=y+dy[i];
if(kx>=1&&kx<=5&&ky>=1&&ky<=5)
dfs(step+1,kx,ky,v*10+a[kx][ky]);
}
return 0;
}
int main()
{
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
dfs(1,i,j,a[i][j]);
printf("%d\n",q.size());
return 0;
}
poj 3050 Hopscotch DFS+暴力搜索+set容器的更多相关文章
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- POJ 3050 Hopscotch DFS
The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of num ...
- POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- poj 2718 Smallest Difference(暴力搜索+STL+DFS)
Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6493 Accepted: 17 ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
随机推荐
- LeetCode 206——链表反转(JAVA)
题目: 反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶:你可 ...
- T100——r类 凭证报表 打印
报表开发流程:1.建立入口程序 如r类的作业:cxmr500步骤: azzi900中建立程序代号 azzi910中建立作业代号 设计器--规格--签出 设计器--程序--签出 adzp168(r.a) ...
- 一次简单的springboot+dubbo+flume+kafka+storm+redis系统
最近无事学习一下,用springboot+dubbo+flume+kafka+storm+redis做了一个简单的scenic系统 scenicweb:展现层,springboot+dubbo sce ...
- Java 代码运行顺序
1.静态代码块,只执行一次,从上到下,先父类后子类 2.父类构造代码块,从上到下,然后父类构造方法,执行次数与实例化次数相关 3.子类构造代码块,从上到下,然后子类构造方法,执行次数与实例化次数相关
- C#:Guid.NewGuid()和DateTime.Now该选择哪个???
直接上代码: namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.WriteLine(& ...
- 数据库HAVING的使用
HAVING语句通常与GROUP BY语句联合使用,用来过滤由GROUP BY语句返回的记录集. HAVING语句的存在弥补了WHERE关键字不能与聚合函数联合使用的不足. 记录一下
- O039、Unshelve Instance 操作详解
参考https://www.cnblogs.com/CloudMan6/p/5529915.html 上一节我们 shelve Instance 到 Glance,本节学习如何通过 unshelv ...
- nginx 配置反向代理和负载均衡
Nginx的配置文件: nginx安装目录/conf/nginx.conf 重新加载配置文件 ./nginx -s reload 配置虚拟主机 一个server就是一台虚拟主机 server { li ...
- django 上传路径至vue处理组件加载
1,在主目录(项目目录)下新建中间件middleware.py文件 写入 from django.utils.deprecation import MiddlewareMixin from djang ...
- OO方式实现ALV: cl_salv_table
这里总结最近用cl_salv_table实现ALV遇到问题和解决办法 FORM set_alv2 . DATA: lv_syrepid TYPE syrepid. lv_syrepid = sy-cp ...