C++ | recursion + memoization
\nclass Solution {\npublic:\n    int mod = 1e9 + 7;\n    \n    int recur(vector<int> &locations , int start , int finish , int fuel , vector<vector<int>> &dp){\
```\nclass Solution {\npublic:\n    int mod = 1e9 + 7;\n    \n    int recur(vector<int> &locations , int start , int finish , int fuel , vector<vector<int>> &dp){\n        \n        if (dp[start][fuel] != -1) return dp[start][fuel];\n        \n        int ans = 0;\n        if (start == finish) ans++;\n        \n        for (int i=0;i<locations.size();i++){\n            if (i == start || abs(locations[i] - locations[start]) > fuel) continue;\n            \n            ans += recur(locations , i , finish , fuel - abs(locations[i] - locations[start]) , dp) % mod;\n            ans %= mod;\n        }\n        \n        return dp[start][fuel] = ans % mod;\n    }\n    \n    int countRoutes(vector<int>& locations, int start, int finish, int fuel) {\n        int sz = locations.size();\n        \n        vector<vector<int>> dp(sz , vector<int>(fuel + 1 , -1));\n        \n        return recur(locations , start , finish , fuel , dp);\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C']