[Java] Bottom up approach in O(n² * fuel)
\nclass Solution {\n    private static final int MOD = (int) 1e9 + 7;\n    \n    public int countRoutes(int[] locations, int start, int finish, int fuel) {\n   
```\nclass Solution {\n    private static final int MOD = (int) 1e9 + 7;\n    \n    public int countRoutes(int[] locations, int start, int finish, int fuel) {\n        int n = locations.length, answer = start == finish ? 1 : 0;\n        int[][] dp = new int[n][fuel + 1];\n        dp[start][0] = 1;\n        \n        for (int i = 1; i <= fuel; i++) {\n            for (int j = 0; j < n; j++) {\n                for (int g = 0; g < n; g++) {\n                    if (g == j) {\n                        continue;\n                    }\n                    \n                    int diff = Math.abs(locations[j] - locations[g]);\n                    if (diff <= i) {\n                        dp[j][i] = (dp[j][i] + dp[g][i - diff]) % MOD;\n                    }\n                }\n            }\n            \n            answer = (answer + dp[finish][i]) % MOD;\n        }\n        \n        return answer;\n    }\n}\n```
[]