Hopscotch
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4385   Accepted: 2924

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.

题意:

对于给定的5x5矩阵,从任意一点开始可重复地走5步所形成的6个数组成数列,问总共可以走多少种。

dfs所有的点,当ans==6时将数列存入set中。

此处将数列转换为6位整数可方便存储。

AC代码:

 //#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std; int a[][];
set<int> st;
int dx[]={,,,-},dy[]={,,-,}; void dfs(int x,int y,int ans,int num){
if(ans==){
st.insert(num);
return ;
}
for(int i=;i<;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=&&nx<&&ny>=&&ny<){
ans++;
dfs(nx,ny,ans,num*+a[nx][ny]);
ans--;
}
}
} int main(){
ios::sync_with_stdio(false);
for(int i=;i<;i++){
for(int j=;j<;j++){
cin>>a[i][j];
}
}
for(int i=;i<;i++){
for(int j=;j<;j++){
dfs(i,j,,a[i][j]);
}
}
cout<<st.size()<<endl;
return ;
}

POJ-3050的更多相关文章

  1. POJ 3050 Hopscotch【DFS带回溯】

    POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...

  2. POJ -3050 Hopscotch

    http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...

  3. POJ 3050 Hopscotch 水~

    http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...

  4. Enum:Hopscotch(POJ 3050)

    跳格子 题目大意:牛像我们一样跳格子,一个5*5的方格,方格有数字,给牛跳5次,可以组成一个6个数字组合字符串,请问能组合多少个字符串? 题目规模很小,暴力枚举,然后用map这个玩具来检测存不存在就可 ...

  5. POJ 3050 穷举

    题意:给定一个5*5的地图,每个格子上有一个数字.从一个格子出发(上下左右4个方向),走5步将数字连起来可以构造出一个6位数.问该地图可以构造出多少个不同的6位数. 分析:可以对每个格子做深度优先遍历 ...

  6. Hopscotch(POJ 3050 DFS)

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

  7. 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 ...

  8. POJ 3050 Hopscotch(dfs,stl)

    用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...

  9. poj 3050 地图5位数问题 dfs算法

    题意:一个5*5地图上面,从任意位置上下左右跳五次,组成一个数.问:不重复的数有多少个? 思路:dfs 从任意位置跳5次,说明每个位置都需要遍历. 组成一个数:number*10+map[dx][dy ...

  10. POJ 3050 枚举+dfs+set判重

    思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...

随机推荐

  1. python 基础 2.1 if 流程控制(一)

    一.if  else 1.if 语句     if expression:   //注意if后有冒号,必须有        statement(s)     //相对于if缩进4个空格 注:pytho ...

  2. Awesome Vue.js vue.js学习资源链接大全 中文

    https://blog.csdn.net/caijunfen/article/details/78216868

  3. Altium Designer 敷铜间距设置,真实有效

    在任一PCB视图时,点击设计->规则,弹出规则设置对话框,如下图 找到Clearance,如下图, 使用右键单击,选择 新规则,如下图 在新规则上单击,在右侧 where  the first ...

  4. getStorageSync const UID = this.$parent.UID wx.getStorageSync('UID')

    getStorageSync  在程序运行中是在内存 还是去文件系统读取?     const UID = this.$parent.UID   wx.getStorageSync('UID')   ...

  5. 504 Gateway Timeout Error 502 Bad Gateway

    总结 1. 502没有收到相应,或者收到了但不及时? cannot get a response in time 540收到了无效的响应 received an invalid response fr ...

  6. Python文件编码不可以使用UTF16

    1. The complete Python source file should use a single encoding. Embedding of differently encoded da ...

  7. 【shell】判断一个变量是否为空

    #!/bin/bash argv=" if [ -z "$argv" ] then echo "argv is empty" else echo &q ...

  8. MySQL——并发控制(锁)

    核心知识点: 1.表锁和行级锁代表着锁的级别:读锁和写锁代表锁定真实类型. 2.读锁属于共享锁,共享同一资源,互不干扰:写锁属于排他锁,为了安全起见,写锁会阻塞其他的读锁和写锁. 3.表锁的开销最小, ...

  9. Matlab的publish功能和cell功能

    Matlab的publish功能能够让写的代码变成优美的文档.类似为知笔记的markdown语言. cell功能配合publish使用,可以形成不同的功能块.而且调试的时候,可以按section调试. ...

  10. javascript(7)

    js中基于对象==js面向对象 js中没有类class,但是它 JavaScript是一种面向(基于)对象的动态脚本语言,是一种基于对象和事件驱动并具有安全性能的脚本语言.它具有面向对象语言所特有的各 ...