JAVA || Dyanimic Programming || Recursion || Memoization
\nclass Solution {\n    int mod = (int) ((1e9)+7);\n    Integer[][] dp = new Integer[104][202];\n    public int solve(int curIdx, int[] locations, int finish, i
```\nclass Solution {\n    int mod = (int) ((1e9)+7);\n    Integer[][] dp = new Integer[104][202];\n    public int solve(int curIdx, int[] locations, int finish, int fuel){\n        int n = locations.length;\n        if(curIdx >= n)\n            return 0;\n        \n        if(dp[curIdx][fuel] != null)\n            return dp[curIdx][fuel];\n        \n        int ret = curIdx == finish ? 1 : 0;\n        for(int i = 0 ; i < n ; i++){\n            if(i != curIdx){\n                int curFuel = fuel - Math.abs(locations[curIdx]-locations[i]);\n                if(curFuel < 0)\n                    continue;\n                \n                // if(i == finish)\n                //     ret++;\n                ret+= (solve(i,locations,finish, curFuel)%mod);\n                ret%=mod;\n            }\n        }\n        dp[curIdx][fuel] = ret;\n        return ret;\n    }\n    \n    public int countRoutes(int[] locations, int start, int finish, int fuel) {\n        int ans = solve(start, locations, finish, fuel);\n        return ans;\n    }\n}\n```
['Recursion', 'Memoization', 'Java']