[挑战程序设计竞赛] POJ 3050 - Hopscotch
来源:互联网 发布:进入数据库的命令 编辑:程序博客网 时间:2024/06/05 17:45
题意:
给定5x5的矩阵。矩阵中的每个点都可以作为起点,每个点可以跳到附近上、下、左、右四个位置。每个位置可以重复跳跃。
问:执行6次操作,可以组合出多少种不同的序列?
DFS简单题~ 把每次搜到的结果存到set容器内,最后输出set元素个数即可。
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <set>#include <map>#include <queue>#include <stack>#include <assert.h>#include <time.h>//#define _Testtypedef long long LL;const int INF = 500000001;const double EPS = 1e-9;const double PI = acos(-1.0);using namespace std;int graph[10][10], dir[4][2] = {-1,0, 1,0, 0,1, 0,-1};set<int> ss;void dfs(int deep, int x, int y, int val){ if(deep == 6) { ss.insert(val); } else for(int i = 0; i < 4; ++i) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if(graph[xx][yy] != -1) { dfs(deep + 1, xx, yy, val * 10 + graph[x][y]); } }}int main(){ #ifdef _Test freopen("test0.in", "r", stdin); freopen("test0.out", "w", stdout); srand(time(NULL)); #endif memset(graph, -1, sizeof(graph)); while(~scanf("%d", &graph[1][1])) { for(int i = 1; i <= 5; ++i) { for(int j = 1; j <= 5; ++j) { if(j != 1 || i != 1) scanf("%d", &graph[i][j]); } } for(int i = 1; i <= 5; ++i) { for(int j = 1; j <= 5; ++j) { dfs(0, i, j, 0); } } printf("%d\n", ss.size()); ss.clear(); } return 0;}
0 0
- [挑战程序设计竞赛] POJ 3050 - Hopscotch
- ACM Hopscotch(挑战程序设计竞赛)
- 挑战程序设计竞赛---POJ.2686
- 挑战程序设计竞赛---POJ.3233
- [挑战程序设计竞赛] POJ 3253 - Fence Repair
- [挑战程序设计竞赛] POJ 3009 - Curling 2.0
- [挑战程序设计竞赛] POJ 3699 - Meteor Shower
- [挑战程序设计竞赛] POJ 2718 - Smallest Difference
- [挑战程序设计竞赛] POJ 2376 - Cleaning Shifts
- [挑战程序设计竞赛] POJ 1328 - Radar Installation
- [挑战程序设计竞赛] POJ 3040 - Allowance
- [挑战程序设计竞赛] POJ 1862 - Stripies
- POJ 1990 MooFest 题解 《挑战程序设计竞赛》
- 挑战程序设计竞赛 poj 2431 优先队列
- POJ 2079 Triangle 题解 《挑战程序设计竞赛》
- POJ 1852 Ants 《挑战程序设计竞赛》1.6
- 挑战2.1 Hopscotch(POJ 3050)
- 《挑战程序设计竞赛》 读后感
- 二维数组中的查找(C语言)
- vs2010 windows service 项目不能引用类库项目
- ANDROID内存优化(大汇总——全)
- 1091. Acute Stroke
- 自学笔记之快速排序
- [挑战程序设计竞赛] POJ 3050 - Hopscotch
- 用四个DIV做四个块成一个田字格布局
- web.xml里面的welcome-file-list是什么意思
- 并查集 HDOJ1856 More is better
- NYoj 79 导弹拦截(dp)
- 多态
- Extjs GridPanel 常用属性总结
- 常用在线java API集合
- 【算法与实现】动态规划(基本思想)