POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050
题目大意:
在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始站的位置算一个,能够走回去)
思路:
近期我就是在做水题。。。
直接DFS就可以。。我用map推断序列是否反复的。
#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int pos[10][10];
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
string ans;
int a[10];
map<string ,int>m; void dfs(int x,int y,int cur)
{
if(cur==6)
{
ans.clear();
for(int i=0;i<6;i++)
ans=ans+(char)a[i];
m[ans]++; return;
} for(int i=0;i<4;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||ny<0||nx>4||ny>4)
continue; a[cur]=pos[nx][ny];
dfs(nx,ny,cur+1);
}
} int main()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
scanf("%d",&pos[i][j]); for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
a[0]=pos[i][j];
dfs(i,j,1);
} printf("%d\n",m.size());
return 0;
}
POJ 3050 Hopscotch 水~的更多相关文章
- 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 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+暴力搜索+set容器
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ.1003 Hangover ( 水 )
POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...
- POJ.1552 Doubles(水)
POJ.1552 Doubles(水) 题意分析 暴力 代码总览 #include <cstdio> #include <stdio.h> #define nmax 100 u ...
随机推荐
- hdoj--迷宫问题
迷宫问题 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submiss ...
- Citrix架构
本图为citrix在Azure上的基本架构 包含了netscaler, VDA, DDC, AD四台服务器以及Azure SQL服务
- Spark Streaming概念学习系列之SparkStreaming性能调优
SparkStreaming性能调优 合理的并行度 减少批处理所消耗时间的常见方式还有提高并行度.有以下三种方式可以提高并行度: 1.增加接收器数目 有时如果记录太多导致单台机器来不及读入并分发的话, ...
- Redis之Ubuntu下Redis集群搭建
安装redis 首先下载redis $ wget http://download.redis.io/releases/redis-4.0.10.tar.gz $ .tar.gz $ cd redis- ...
- 对比JavaScript的入口函数和jQuery的入口函数
JavaScript的入口函数要等到页面中所有的资源(包括图片.文件)加载完成才开始执行. jQuery的入口函数只会等待文档数加载完成就开始执行,并不会等待图片.文件的加载.
- Android--XML页面的编写
五个页面 代码如下: 图片资源链接: https://pan.baidu.com/s/1jIoTDGE // 第一个 <RelativeLayout xmlns:andr ...
- MongoDB 博客截图之一
来源:十天掌握MongoDB之三:学会Find - 学吧网 - 专注于PHP资源分享
- python第三方模块大杂烩
Python单元测试框架之pytest---如何执行测试用例 unittest单元测试框架实现参数化 (用例有相似参数断言时使用,可以精简代码) python中标示符作用详解 一篇文章让你彻底搞清楚P ...
- ML一:python的KNN算法
(1):list的排序算法: 参考链接:http://blog.csdn.net/horin153/article/details/7076321 示例: DisListSorted = sorted ...
- 知识工程.Vs.软件构架,框架,设计模式.
软件工程-原文链接:http://tech.it168.com/a2009/0902/672/000000672853.shtml 此文章详细给出了软件设计的基本概念和用途,文章链接:http://w ...