Leetcode-5215 Path with Maximum Gold(黄金矿工)
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-5215 Path with Maximum Gold(黄金矿工)相关的知识,希望对你有一定的参考价值。
1 typedef long long ll; 2 typedef pair<int,int> P; 3 #define _for(i,a,b) for(register int i = (a);i < b;i ++) 4 #define _rep(i,a,b) for(register int i = (a);i > b;i --) 5 #define INF 0x3f3f3f3f 6 #define MOD 100000000 7 #define maxn 10003 8 9 const int dx[] = 1,-1,0,0; 10 const int dy[] = 0,0,1,-1; 11 class Solution 12 13 public: 14 15 int vis[100][100]; 16 vector<vector<int>> v; 17 int ans = 0; 18 bool valid(int x,int y) 19 20 return x>=0 && x<v.size() && y>=0 && y<v[0].size(); 21 22 void dfs(int x,int y,int get) 23 24 ans = max(ans,get); 25 _for(i,0,4) 26 27 int nx = x+dx[i]; 28 int ny = y+dy[i]; 29 if(valid(nx,ny) && !vis[nx][ny] && v[nx][ny]) 30 31 vis[nx][ny] = 1; 32 dfs(nx,ny,get+v[nx][ny]); 33 vis[nx][ny] = 0; 34 35 36 37 int getMaximumGold(vector<vector<int>>& grid) 38 39 v = grid; 40 _for(i,0,grid.size()) 41 _for(j,0,grid[i].size()) 42 if(v[i][j]) 43 44 memset(vis,0,sizeof(vis)); 45 vis[i][j] = 1; 46 dfs(i,j,v[i][j]); 47 48 return ans; 49 50 ;
以上是关于Leetcode-5215 Path with Maximum Gold(黄金矿工)的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 1219. Path with Maximum Gold
[LC] 1219. Path with Maximum Gold
LeetCode 1293. Shortest Path in a Grid with Obstacles Elimination
leetcode_1293. Shortest Path in a Grid with Obstacles Elimination_[dp动态规划]