POJ 3050
来源:互联网 发布:张宇唱功知乎 编辑:程序博客网 时间:2024/04/29 03:40
题意:从一个起点,走5步,能组成几个六位数
题解:
用set直接排除重复项最easy,爆搜每一个起点
dfs(int x,int y,int step,int s)if(step==5){ if(ansset.find(s)==ansset.end()){ ansset.insert(s); } return;}
实际上并不需要判断,因为set不会装重复元素
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<queue>#define pr(x) cout<<#x<<" "<<x;#define pl(x) cout<<#x<<" "<<x<<endl;#include<math.h>#include<algorithm>#include<set>#include<map>#include<bitset>#include<string>#include<cstring>#include<sstream>using namespace std;int maze[5][5];set<int> ansset;int dx[] = {-1,1,0,0};int dy[] = {0,0,-1,1};bool isin(int x,int y){ if(x>=0&&x<5&&y>=0&&y<5){return true;} else{return false;}}void dfs(int x,int y,int step,int s){ if(step==5){ if(ansset.find(s)==ansset.end()){ ansset.insert(s); } return; } for(int i =0;i<4;i++){ int nx = x + dx[i]; int ny = y + dy[i]; if(isin(nx,ny)){ dfs(nx,ny,step+1,s*10+ maze[nx][ny]); } }}int main(){ for(int i = 0;i<5;i++){ for(int j = 0;j<5;j++){ cin>>maze[i][j]; } } for(int i = 0;i<5;i++){ for(int j = 0;j<5;j++){ dfs(i,j,0,maze[i][j]); } } cout<<ansset.size()<<endl;}
0 0
- poj 3050
- POJ 3050
- POJ 3050
- poj-3050
- POJ-3050
- 【POJ】3050
- poj 3050 搜索
- POJ 3050 Hopscotch
- poj 3050 Hopscotch DFS
- poj 3050 Hopscotch
- POJ-3050-Hopscotch
- poj 3050 Hopscotch
- POJ 3050 Hopscotch 水~
- POJ 3050 Hopscotch
- POJ-3050 Hopscotch
- POJ 3050 Hopscotch DFS
- POJ 3050 Hopscotch
- POJ 3050 Hopscotch
- STL中map的operator[ ]使用方法
- Flash芯片的种类与区别
- [线性DP]轮渡问题(LIS应用)
- Audio驱动开发 之 音频链路学习笔记
- 三种ViewController跳转的异同
- POJ 3050
- linux磁盘分区问题
- 单链表是否有环,求环起点,环长等
- test
- Saving HDU
- 缓冲区溢出与数据执行保护DEP介绍
- 剑指offer 二叉搜索树与双向链表
- Java虚拟机知识整理——方法调用
- 6、Java多线程机制