思路:

枚举+搜一下+判个重 ==AC

//By SiriusRen
#include <set>
#include <cstdio>
using namespace std;
int a[8][8],xx[]={1,-1,0,0},yy[]={0,0,1,-1};
set<int>s;
bool check(int x,int y){
return x>0&&x<6&&y>0&&y<6;
}
void dfs(int x,int y,int deep,int num){
if(deep==6){s.insert(num);return;}
for(int i=0;i<4;i++)
if(check(x+xx[i],y+yy[i]))
dfs(x+xx[i],y+yy[i],deep+1,num*10+a[x+xx[i]][y+yy[i]]);
}
int main(){
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
dfs(i,j,1,a[i][j]);
printf("%llu\n",s.size());
}

POJ 3050 枚举+dfs+set判重的更多相关文章

  1. hdu 2610 2611 dfs的判重技巧

    对于全排列枚举的数列的判重技巧 1:如果查找的是第一个元素 那么 从0开始到当前的位置看有没有出现过这个元素 出现过就pass 2: 如果查找的不是第一个元素 那么 从查找的子序列当前位置的前一个元素 ...

  2. POJ 3050 Hopscotch(dfs,stl)

    用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...

  3. 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1675 一开始我写了个枚举7个点....... 但是貌似... 写挫了. 然后我就写dfs.. 判重好 ...

  4. POJ 1753 (枚举+DFS)

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40632   Accepted: 17647 Descr ...

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

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

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

  7. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  8. POJ 2458 DFS+判重

    题意: 思路: 搜+判重 嗯搞定 (听说有好多人用7个for写得-.) //By SiriusRen #include <bitset> #include <cstdio>0 ...

  9. UVa 10400 - Game Show Math 游戏中的数学 dfs+判重

    题意:给出一些数字和一个目标数字,要求你在数字间添加+-*/,让表达式能达到目标数字,运算符号的优先级都是一样的. 由于数据量很大,本来想用map<string>判重的,结果还是超时了,然 ...

随机推荐

  1. <Sicily>Catch the thief

    一.题目描述 A thief has robbed a bank in city 1 and he wants to go to city N. The police know that the th ...

  2. PHP——下载图片到本地代码

    <?php //获取网页图片 $url = "http://qlogo2.store.qq.com/qzone/393183837/393183837/50"; $curl ...

  3. php文件加载、错误处理、方法函数和数组

    数组运算符注意:php中,数组的元素的顺序,不是由下标(键名)决定的,而是完全由加入的顺序来决定.联合(+):将右边的数组项合并到左边数组的后面,得到一个新数组.如有重复键,则结果以左边的为准$v1 ...

  4. session 存入 memcahce

    <?php header('content-type:text/html;charset=utf-8'); class RedisSessionHandler{ public $ttl; //失 ...

  5. 【Codeforces Round #465 (Div. 2) C】Fifa and Fafa

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 这个x2,y2和圆心(x1,y1)相连.形成的直线和圆交于点(x3,y3) 则(x2,y2)和(x3,y3)的中点就是所求圆的圆心. ...

  6. 查看mysql正在执行的SQL语句,使用profile分析SQL执行状态

    http://qq85609655.iteye.com/blog/2113960 1)我们先通过status命令查看Mysql运行状态 mysql> status; -------------- ...

  7. Maven的SSH搭建以及部署

    本人有点傻,研究Maven研究了有一段时间,刚刚有些入门,记录下来方便以后使用 工作环境:jdk7 myeclipse10 maven3.1.1 1 下载maven3.1.1 http://maven ...

  8. HDU Victor and World (最短路+状态压缩)

    题目链接:传送门 题意: n个城市m条路.刚開始在点1,求把每一个城市都遍历一边最后回到1的花费的最小值. 分析: ​​+n​2​​∗2​n​​). 转自Bestcode. 以下说说我的状态转移,首先 ...

  9. 4.graph.h

    #pragma once #include <stdio.h> #include <graphics.h> #include <mmsystem.h> #pragm ...

  10. BZOJ 3196 线段树套平衡树

    (代码无比丑陋) //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int ...