How to solve gold mine problem with dynamic programming

Hi everyone, i want to solve the problem below with dynamic programming but i dont know where to start. Can anyone suggest me something? So the problem is about the find the minimum path with maximums golds. This is the code i have tried so far but it gets me nowhere. if anyone can help me, im really appreciated

public static int getMaxGold(String[][] maze) {
        int m = maze.length;
        int n = maze[0].length;
        int right = 0;
        int down = 0;
        String[][] gold = new String[maze.length][maze[0].length];
        for (String[] row : gold) {
            Arrays.fill(row, String.valueOf(0));
        }
        for (int col = 0; col < n; col++) {
            for (int row = 0; row < m; row++) {
                if (String.valueOf(right).equals("X") || String.valueOf(right).equals(".")) {
                    right = 0;
                } else {
                    right = (col == n-1) ? 0 : Integer.parseInt(maze[row][col+1]);
                }
                if (String.valueOf(down).equals("X") || String.valueOf(down).equals(".")) {
                    down = 0;
                } else {
                    down = (row == m-1 || col == n-1) ? 0 : Integer.parseInt(maze[row+1][col+1]);
                }
                gold[row][col] = gold[row][col] + Math.max(right, down);
            }
        }
        int res = Integer.parseInt(gold[0][0]);
        for (int i = 1; i < m; i++) {
            res = Math.max(res, Integer.parseInt(gold[i][0]));
        }
        return res;
    }

Screenshot_2021-12-07_084709.jpg

Screenshot_2021-12-07_084900.jpg