POJ 3050 枚举+dfs+set判重
思路:
枚举+搜一下+判个重 ==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判重的更多相关文章
- hdu 2610 2611 dfs的判重技巧
对于全排列枚举的数列的判重技巧 1:如果查找的是第一个元素 那么 从0开始到当前的位置看有没有出现过这个元素 出现过就pass 2: 如果查找的不是第一个元素 那么 从查找的子序列当前位置的前一个元素 ...
- POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)
http://www.lydsy.com/JudgeOnline/problem.php?id=1675 一开始我写了个枚举7个点....... 但是貌似... 写挫了. 然后我就写dfs.. 判重好 ...
- POJ 1753 (枚举+DFS)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40632 Accepted: 17647 Descr ...
- 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 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 ...
- POJ 2458 DFS+判重
题意: 思路: 搜+判重 嗯搞定 (听说有好多人用7个for写得-.) //By SiriusRen #include <bitset> #include <cstdio>0 ...
- UVa 10400 - Game Show Math 游戏中的数学 dfs+判重
题意:给出一些数字和一个目标数字,要求你在数字间添加+-*/,让表达式能达到目标数字,运算符号的优先级都是一样的. 由于数据量很大,本来想用map<string>判重的,结果还是超时了,然 ...
随机推荐
- RMAN动态视图
1.V$ARCHIVEG_LOG 显示归档文件在数据库中创建.备份.清除 2.V$BACKUP_CORRUPTION 显示当一个备份集备份时块中发现的坏块 3.V$COPY_CORRUPTION 显示 ...
- python3.x学习笔记3(基础知识)
1.集合集合是一个无序的,不重复的数据组合,作用如下: >>去重,把一个列表变成集合,就自动去重 >>关系测试,测试两组数据之前的交集.差集.并集等关系 2.关系运算 交集: ...
- 实体转XML XML转实体
// <summary> /// 实体类序列化成xml /// </summary> /// <param name="enitities">实 ...
- Sql Server 基本数据类型
第一大类:整数数据 bit:bit数据类型代表0,1或NULL,就是表示true,false.占用1byte. int:以4个字节来存储正负数.可存储范围为:-2^31至2^31-1. smallin ...
- UVa 10305 Ordering Tasks【拓扑排序】
题意:给出n件事情,m个二元组关系,求它们的拓扑序列 用的队列来做 #include<iostream> #include<cstdio> #include<cstrin ...
- UI Framework-1: UI Development Practices
UI Development Practices Guidelines Principles for developing for Chrome. These best practices cente ...
- mac ssh报错处理
总结一下 1.The authenticity of host '[192.168.1.100]:22 ([192.168.1.100]:22)' can't be established. RSA ...
- vue动态绑定img标签的src地址
问题代码: <li v-for="(item,index) in images" :key="index"> <img :src=" ...
- bzoj1618 购买干草
Description 约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草.他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重量为Pi(1≤Pi ...
- js 快捷键设置
function hotkey() { var a=window.event.keyCode; if((a==65)&&(event.ctrlKey)) { alert("你 ...