POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重。dfs一遍就好。(或者编码成int,快排+unique
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std; const int maxn = ;
int g[maxn][maxn]; bool inside(int x,int y)
{
return x>=&&x<maxn&&y>=&&y<maxn;
} set<stack<int> > S;
stack<int> stk;
const int dx[] = {,,-,}, dy[] = {,-,,};
void dfs(int x,int y)
{
if(!inside(x,y)) return;
if(stk.size() == ){
S.insert(stk);
return ;
}
for(int i = ; i < ; i++){
int nx = x+dx[i], ny = y+dy[i];
if(inside(nx,ny)){
stk.push(g[nx][ny]);
dfs(nx,ny);
stk.pop();
}
}
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
for(int i = ; i < maxn; i++){
for(int j = ; j < maxn; j++){
scanf("%d",g[i]+j);
}
}
for(int i = ; i < maxn; i++)
for(int j = ; j < maxn; j++)
dfs(i,j);
printf("%d\n",S.size());
return ;
}
POJ 3050 Hopscotch(dfs,stl)的更多相关文章
- poj 3050 Hopscotch DFS+暴力搜索+set容器
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...
- 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带回溯】
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个数的序列一共同拥有多少种?(一開始 ...
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- POJ 3050 枚举+dfs+set判重
思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...
- POJ.3172 Scales (DFS)
POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以 ...
- Hopscotch(POJ 3050 DFS)
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2845 Accepted: 1995 Descrip ...
随机推荐
- Yaf + Smarty 整合笔记
Yaf真的是太简单了,简单到使用mvc的时候在view里面需要手写php脚本.因此考虑整合一下smarty模板引擎.随心所欲也正是yaf的魅力 Yaf 安装 这里简单说一下yaf的安装,已经是非常无脑 ...
- bzoj2724: [Violet 6]蒲公英(分块)
传送门 md调了一个晚上最后发现竟然是空间开小了……明明算出来够的…… 讲真其实我以前不太瞧得起分块,觉得这种基于暴力的数据结构一点美感都没有.然而今天做了这道分块的题才发现分块的暴力之美(如果我空间 ...
- EIGRP-3-EIGRP的多参数度量
带宽度量参数本身无法区分10Gbit/s及更高速率的接口.对1Gbit/s接口,默认延迟度量参数已设置为最低值1(10微妙).而且EIGRP承载的是经过换算的参数,每台路由器需要将其换算回再计算新开销 ...
- python依赖文件
生成 pip freeze >requirements.txt 安装 pip install -r requirements.txt
- 使用navicat把一个数据库的表导入到另外一个数据库
第一步:右击数据库名,选择数据传输 第二步:全选要导的数据库表 第三步:选择目标中的数据库,然后开始就可以了
- 怎么在Vue中使用Base64格式的背景
问题发生于一次mock数据,生成了base64格式的东西,因为编码包在一个变量中,不知道怎么直接在 :style 中引入. 解答1:格式background-image: url(此处是我们mock生 ...
- springboot和Druid整合配置数据源
@Configuration public class DruidConfiguration { @ConfigurationProperties(prefix = "spring.data ...
- MD5-UTF8-大写加密
private string GetMD5Hash(string str) { string md5Str = ""; byte[] buffer = Encoding.UTF8. ...
- Linux--1 初识
一.服务器核心知识 1.电脑和电脑的硬件组成 现在的人们几乎无时无刻不在使用着电脑!不管是桌上型电脑(桌机).笔记型电脑(笔电).平板电脑,还是智慧型手机等等,这些东西都算是电脑.虽然接触这么多,但是 ...
- beeline连接hive
beeline -u jdbc:hive2://192.168.1.77:10000 zeppelin default jdbc: jdbc:hive2://nn01.ooccpp.com:2181/ ...