[Java] Bottom Up
\nclass Solution {\n    public int countRoutes(int[] locations, int start, int finish, int fuel) {\n        long[][] dp = new long[locations.length][fuel+1];\n 
```\nclass Solution {\n    public int countRoutes(int[] locations, int start, int finish, int fuel) {\n        long[][] dp = new long[locations.length][fuel+1];\n        long MOD = (long)(1e9 + 7);\n        Arrays.fill(dp[finish],1);\n        long ans = 0;\n        for(int j = 0; j <= fuel; j++) {\n            for(int i = 0; i < locations.length; i++) {\n                for(int k = 0; k < locations.length; k++) {\n                    if(k == i) continue;\n                    if(Math.abs(locations[i] - locations[k]) <= j) {\n                        dp[i][j] = (dp[i][j] + dp[k][j - Math.abs(locations[i] - locations[k])]) % MOD; \n                    }\n                }\n            }\n        }\n        return (int)dp[start][fuel];\n    }\n}\n```
['Dynamic Programming', 'Java']