用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)的更多相关文章

  1. poj 3050 Hopscotch DFS+暴力搜索+set容器

    Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...

  2. 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 ...

  3. POJ 3050 Hopscotch【DFS带回溯】

    POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...

  4. POJ -3050 Hopscotch

    http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...

  5. POJ 3050 Hopscotch 水~

    http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...

  6. POJ 3050 Hopscotch 四方向搜索

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6761   Accepted: 4354 Descrip ...

  7. POJ 3050 枚举+dfs+set判重

    思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...

  8. POJ.3172 Scales (DFS)

    POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以 ...

  9. Hopscotch(POJ 3050 DFS)

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Descrip ...

随机推荐

  1. 浅谈JavaScript--事件委托与事件监听

    事件监听 该方法用于向指定元素添加事件句柄(代码块),且不会覆盖已存在的事件句柄. 即可以向同一个元素添加同一个事件多次. 添加事件 语法: element.addEventListener(even ...

  2. 2017-9-26 NOIP模拟赛

    NOIP 2017 全真模拟冲刺 ---LRH&&XXY 题目名称 那些年 铁路计划 毁灭 题目类型 传统 传统 传统 可执行文件名 years trainfare destroy 输 ...

  3. EIGRP-3-EIGRP的多参数度量

    带宽度量参数本身无法区分10Gbit/s及更高速率的接口.对1Gbit/s接口,默认延迟度量参数已设置为最低值1(10微妙).而且EIGRP承载的是经过换算的参数,每台路由器需要将其换算回再计算新开销 ...

  4. 我的Android Studio配置

    Android Studio固然好用,但是刚从Eclipse转移到Android Studio上难免有很多不便,现在集中整理一下AS与Eclipse的区别,使得AS更好用. 快捷键Keymap到Ecl ...

  5. 1105 Spiral Matrix(25 分)

    This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasi ...

  6. 1093 Count PAT's(25 分)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  7. 源码分析ConcurrentHashMap

    ConcurrentHashMap 1.7 segment分段锁 1.8 CAS 红黑树

  8. mitmproxy——抓取http、https

    mitmproxy是一个支持HTTP和HTTPS的抓包程序,有类似Fiddler.Charles的功能.除了命令行形式的控制台,mitmproxy还有两个关联组件:mitmdump和mitmweb. ...

  9. strcpy、strncpy、strlen、memcpy、memset、strcat、strncat、strcmp、strncmp,strchr

    1.strcpy #include<stdio.h> #include<assert.h> char *mystrcpy(char *dest, const char *src ...

  10. 009 Palindrome Number 判断一个正整数是否是回文数

    详见:https://leetcode.com/problems/palindrome-number/description/ 实现语言:Java 方法一: class Solution { publ ...