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 };

 

上一篇:EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS的删除创建


下一篇:Java中的static(1)【持续更新】——关于Eclipse的No enclosing instance of type ... 错误的理解和改正