🏆C++ || DP (recursion + memoization)
Code\n\nclass Solution {\npublic:\n    long long mod=1e9+7;\n    int help(vector<int>&locations,int s,int f,int fuel,vector<vector<int>>&dp){\n        if(dp[s][
# Code\n```\nclass Solution {\npublic:\n    long long mod=1e9+7;\n    int help(vector<int>&locations,int s,int f,int fuel,vector<vector<int>>&dp){\n        if(dp[s][fuel]!=-1)return dp[s][fuel];\n        int ans=0;\n        if(s==f){\n            ans = (ans%mod + 1)%mod;\n        }\n        for(int i=0;i<locations.size();i++){\n            int price = abs(locations[s]-locations[i]);\n            if(fuel-price>=0 && i!=s){\n                ans = (ans%mod + help(locations,i,f,fuel-price,dp)%mod)%mod;\n            }\n        }\n        return dp[s][fuel]=ans;\n    }\n    int countRoutes(vector<int>& locations, int start, int finish, int fuel) {\n     vector<vector<int>>dp(locations.size()+1,vector<int>(fuel+1,-1));\n     return help(locations,start,finish,fuel,dp);\n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/97c0c9c0-4e7a-4127-be9d-7b75f703af87_1687682221.217803.jpeg)\n
['C++']