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 ...
随机推荐
- 【POJ 4007】 Flood-it!
[题目链接] http://poj.org/problem?id=4007 [算法] IDA* [代码] #include <algorithm> #include <bitset& ...
- [计蒜客] tsy's number 解题报告 (莫比乌斯反演+数论分块)
interlinkage: https://nanti.jisuanke.com/t/38226 description: solution: 显然$\frac{\phi(j^2)}{\phi(j)} ...
- Netty简单介绍(非原创)
文章大纲 一.Netty基础介绍二.Netty代码实战三.项目源码下载四.参考文章 一.Netty基础介绍 1. 简介 官方定义为:”Netty 是一款异步的事件驱动的网络应用程序框架,支持快速地 ...
- NOIP2012 D2 T2 借教室 线段树 OR 二分法
题目描述: 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自 ...
- 阿里云 linux centos 常用解压命令
格式: tar 选项 文件目录列表 功能: 对文件目录进行打包备份 选项: -c 建立新的归档文件 -r 向归档文件末尾追加文件 -x 从归档文件中解出文件 -O 将文件解开到 ...
- UI常用网站
网站大全 国外的花瓣--Pinterest • The world’s catalog of ideas 字体海洋--求字体网提供中文和英文字体库下载.识别与预览服务,找字体的好帮手 原创设计UI-- ...
- Surround the Trees[HDU1392]
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 如何在Hexo中实现自适应响应式相册功能
用最清晰简洁的方法整合一个响应式相册 效果 技术选型 由于我选用的主题使用了fancyBox作为图片弹出展示的框架,查看后表示很不错,能满足需要 http://fancyapps.com/fancyb ...
- (转)19 个 JavaScript 有用的简写技术
1.三元操作符 当想写if...else语句时,使用三元操作符来代替. const x = 20; let answer; if (x > 10) { answer = 'is greater' ...
- hdu2853 Assignment 完美匹配 多校联赛的好题
PS:好题.不看题解绝对AC不了. 题解来源: http://blog.csdn.net/niushuai666/article/details/7176290 http://www.cnblogs. ...