我是靠谱客的博主 鳗鱼眼睛,这篇文章主要介绍蓝桥杯 (计算路径),现在分享给大家,希望可以做个参考。

 题意:7*7的矩阵,出发点和终点都是0,0 ,问有多少条路径,步数不超过12步。

 考虑的边界值不仅仅是迷宫边界,还有最少步数,所有的限制条件都要考虑

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define lli long long #define pq priority_queue<int> #define pql priority_queue<ll> #define pqn priority_queue<node> #define v vector<int> #define vl vector<ll> #define read(x) scanf("%d",&x) #define read2(x,y) scanf("%d %d",&x,&y); #define lread(x) scanf("%lld",&x); #define pt(x) printf("%dn",(x)) #define yes printf("YESn"); #define no printf("NOn"); #define gcd __gcd #define out(x) cout<<x<<endl; #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++) #define input(k) for (int i = 1; i <= (int)(k); i++) {scanf("%d",&a[i]) ; } #define mem(s,t) memset(s,t,sizeof(s)) #define ok return 0; #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test cout<<" ++++++ "<<endl; //二叉树 #define lson rt<<1, l, m #define rson rt<<1|1, m+1, r //线段树 #define ls now<<1 #define rs now<<1|1 const int inf = 1e6+5; int vis[8][8],cnt=0,ans; int dir[4][2] = {1,0,-1,0,0,1,0,-1}; void DFS(int x,int y) { if(ans>12) return ; if(x==1 && y==1 && ans>2) {cnt++;return ;} for(int i=0;i<4;i++) { int nx=x+dir[i][0]; int ny=y+dir[i][1]; if(nx<1 || ny<1 || nx > 7 || ny>7 ) continue; if(!vis[nx][ny] ) { vis[nx][ny]=1; ans++; DFS(nx,ny); ans--; vis[nx][ny]=0; } } } int main() { mem(vis,0); ans=0; DFS(1,1); cout<<cnt<<endl; }

 

转载于:https://www.cnblogs.com/Shallow-dream/p/11545015.html

最后

以上就是鳗鱼眼睛最近收集整理的关于蓝桥杯 (计算路径)的全部内容,更多相关蓝桥杯内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部