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. NERO8.0刻录系统光盘

    正常启动NREO,点击NERO 8.0左下角图标(启动NERO应用程序和工具),选NERO Express Essentials,在左边的几个选项中选择“映像.项目.复制”,右边选“光盘映像或保存的项 ...

  2. DBUtils使用详解

    https://blog.csdn.net/samjustin1/article/details/52220423 https://www.cnblogs.com/CQY1183344265/p/58 ...

  3. 深入了解Cookie(1)------selenium2进行Cookie操作的前奏

    世界上最宽阔的是海洋,比海洋还宽阔的是天空,比天空还宽阔的是人的心量.做人的心量有多大.人生的成就就有多大. 不为一己之利去争.去斗.去夺,扫除报复之心和妒忌之念.自然"心底无私天地宽&qu ...

  4. Java for LeetCode 108 Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 解题 ...

  5. redis安装包下载

    redis linux版安装包下载地址 http://download.redis.io/releases/

  6. Android Weekly Notes Issue #322

    Android Weekly Issue #322 August 12th, 2018 Android Weekly Issue #322. 本期内容包括: 键盘的图像支持; 网络安全实现; Kotl ...

  7. Android系统Gps分析(一)【转】

    本文转载自:http://blog.csdn.net/xnwyd/article/details/7198728 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   1 G ...

  8. consider increasing the maximum size of the cache.

    虚拟机上搭建jenkins,出现unable to free [10] percent of the cache for Context [/jenkins] 提示让我加大缓存 consider in ...

  9. swoole+nginx反向代理

    nginx配置: server { listen 80; server_name www.swoole.com; root /data/wwwroot/www.swoole.com; location ...

  10. JavaScript里值比较的方法

    JavaScript里值比较的方法 参考资料 一张图彻底搞懂JavaScript的==运算 toString()和valueof()方法的区别 Object.is 和 == 与 === 不同 == 运 ...