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 ...
随机推荐
- Swift - 将字符串拆分成数组(把一个字符串分割成字符串数组)
在Swift中,如果需要把一个字符串根据特定的分隔符拆分(split)成字符串数组,通常有如下两种方法: 1,使用componentsSeparatedByString()方法 1 2 3 4 5 l ...
- LightOJ--1152--Hiding Gold(二分图奇偶建图)(好题)
Hiding Gold Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Submit Sta ...
- hdoj--1864--最大保险额(背包)
最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- Kaggle爆文:一个框架解决几乎所有机器学习问题
上周一个叫 Abhishek Thakur 的数据科学家,在他的 Linkedin 发表了一篇文章 Approaching (Almost) Any Machine Learning Proble ...
- Python金融量化
Python股票数据分析 最近在学习基于python的股票数据分析,其中主要用到了tushare和seaborn.tushare是一款财经类数据接口包,国内的股票数据还是比较全的 官网地址:http: ...
- Arduino-1602-LiquidCrystal库
前言:LiquidCrystal是一个1602的IIC库,使用IIC协议可以极大节约用线数量,十分方便.当然,前提是1602要使用LCD1602 I2C模块. 一.库函数快速查询 LiquidCrys ...
- cookie,session,viewstate
viewstate的原理是隐藏域. protected void Page_Load(object sender, EventArgs e) { ViewState["v1"] = ...
- hihoCoder挑战赛32
Rikka with Sequence V 构造 #pragma comment(linker, "/STACK:102400000,102400000") #include< ...
- 实践:使用FLANN.LSH进行检索
1.Survey: FLANN 库详情见:http://en.wikipedia.org/wiki/Flann http://medievalscotland.org/kmo/AnnalsIndex/ ...
- Kinect安装与配置(openNI2)
原文链接:http://blog.csdn.net/chenxin_130/article/details/8580636 简介 最近OpenNI2的推出,小斤也要多给博客除除草了,并在闲暇之余做一些 ...