POJ-3050
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 lineOutput
* Line 1: The number of distinct integers that can be constructedSample 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 1Sample Output
15Hint
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的更多相关文章
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- 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个数的序列一共同拥有多少种?(一開始 ...
- Enum:Hopscotch(POJ 3050)
跳格子 题目大意:牛像我们一样跳格子,一个5*5的方格,方格有数字,给牛跳5次,可以组成一个6个数字组合字符串,请问能组合多少个字符串? 题目规模很小,暴力枚举,然后用map这个玩具来检测存不存在就可 ...
- POJ 3050 穷举
题意:给定一个5*5的地图,每个格子上有一个数字.从一个格子出发(上下左右4个方向),走5步将数字连起来可以构造出一个6位数.问该地图可以构造出多少个不同的6位数. 分析:可以对每个格子做深度优先遍历 ...
- Hopscotch(POJ 3050 DFS)
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2845 Accepted: 1995 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 地图5位数问题 dfs算法
题意:一个5*5地图上面,从任意位置上下左右跳五次,组成一个数.问:不重复的数有多少个? 思路:dfs 从任意位置跳5次,说明每个位置都需要遍历. 组成一个数:number*10+map[dx][dy ...
- POJ 3050 枚举+dfs+set判重
思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...
随机推荐
- 10个迷惑新手的Cocoa&Objective-c开发问题
本文转载至 http://blog.csdn.net/lvxiangan/article/details/27964733 language background runtime thre ...
- ICMP控制报文协议
1.引言 ICMP经常被认为是IP层的一个组成部分.它传递差错以及其他需要注意的信息.ICMP报文通常被IP层或更高层 协议(TCP或UDP)使用.一些ICMP报文把差错报文返回给用户进程.ICMP报 ...
- 九度OJ 1178:复数集合 (插入排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8393 解决:1551 题目描述: 一个复数(x+iy)集合,两种操作作用在该集合上: 1.Pop 表示读出集合中复数模值最大的那个复数,如 ...
- 在WePY中实现了小程序的组件化开发,组件的所有业务与功能在组件本身实现,组件与组件之间彼此隔离,上述例子在WePY的组件化开发过程中,A组件只会影响到A所绑定的myclick
wepyjs - 小程序组件化开发框架 https://tencent.github.io/wepy/document.html#/?id=%e5%be%ae%e4%bf%a1%e5%b0%8f%e7 ...
- 洛谷2483 k短路([SDOI2010]魔法猪学院)
题目请戳这里 一句话题意: 给你一张n个节点,m条单向边的图,求1到n第k短的路. emmm,纪念第一个黑题(我是真的菜啊!!) 这题目还是很难的,本蒟蒻只会被洛谷卡掉的A(所以就愉快地特判了),首先 ...
- Android开发之ListView添加多种布局效果演示
在这个案例中展示的新闻列表,使用到ListView控件,然后在适配器中添加多种布局效果,这里通过重写BaseAdapter类中的 getViewType()和getItemViewType()来做判断 ...
- php 文件头部(header)
发布:sunday01 来源:net [大 中 小] 有关php文件头部信息(header)的详细介绍,是脚本学堂见过的最详细的一篇,有需要的朋友,千万不要错过这么好的文章. php文件头 ...
- ruby 正则表达式
Ruby学习笔记-正则表达式 Posted on 2011-11-29 17:55 Glen He 阅读(4998) 评论(0) 编辑 收藏 1.创建正则表达式 a) reg1 = /^[a-z]*$ ...
- property 中的strong 与weak
strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *string1; @property ...
- Java多线程系列 基础篇01 线程的状态
1.进程和线程 进程: 计算机中程序关于某数据集合的一次运行活动,是计算机系统进行资源分配和调度的基本单位,是操作系统结构的基础. 线程: 线程是进程的实例,是CPU进行资源分配和调度的最小单位,线程 ...