用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. springmvc ajax 简单例子

    1.控制器曾 @Controller public class AjaxController { @RequestMapping("/ajax") public void ajax ...

  2. d190305面试01过程记录和总结(java开发)

    1.签到,做题,注意时间.(疑问:做笔试题的时候,没有人监管吗?作弊怎么办) 2.今天做的是比较基础的题,题型有判断题(8),选择题(10),简答题(3),编程(2)逻辑题(2) (ps:感觉做的还不 ...

  3. AT2348 HonestOrUnkind

    传送门 显然\(a>b\)的情况下才有解 考虑先找出一个诚实的人,然后剩下的都可以在\(n\)次以内问出来了 发现如果一个人说另一个人是说谎的那么这两个人必有一个是说谎的,由于诚实的人严格多于不 ...

  4. Jmeter_拦截Excel文件输出流到本地

    一般而言,对于页面的“导出”操作,主要经历如下两个操作:①根据数据库的内容,将文件导出到应用服务器上:②将服务器上的文件下载到本地电脑: Jmeter同LoadRunner类似,只能记录服务端与客户端 ...

  5. 关于node中的global,箭头函数的this的一个小问题

    this一直是一个JS中的困扰问题,这次在跑JS精粹的代码的时候顺带发现了Node里面全局变量的问题 var x = 1; var myObj = { x: 2 }; myObj.func = fun ...

  6. 从select机制谈到epoll机制

    目录 为什么要用select机制 等待队列 唤醒操作 什么是select机制 关于fd_set select使用 poll函数 为什么select效率较低 什么是epoll epoll机制实现思路 e ...

  7. ContOS7分区并挂载硬盘(gpt)

    parted fdisk [只支持MSDOS分区布局] parted [支持MSDOS.GPT分区布局] 分区有三个步骤: 第一个步骤就是用分区工具进行分区 第二个步骤就是创建文件系统(也就是格式化) ...

  8. lintcode-dfs实现二叉树的层序遍历

    class Solution { /** * @param root: The root of binary tree. * @return: Level order a list of lists ...

  9. 11 Lists

    1       Lists 1.1  定义并访问Lists List list = new List[].也可以使用泛型.访问list中的元素,可以使用list.get(i) or list[i]. ...

  10. 转 GTID复制的搭建和问题处理

    ########sample 1: 了解mysqldump 和 mysqlbackup  和 gtid_executed 和 gtid_purged https://www.linuxidc.com/ ...