C++ | Easy Top down approach
\n#define mod 1000000007\n#define ll long long\nclass Solution {\npublic:\n\nll count(vector<int> &loc,int str,int fin,int fuel,vector<vector<ll>> &dp)\n{      
```\n#define mod 1000000007\n#define ll long long\nclass Solution {\npublic:\n\nll count(vector<int> &loc,int str,int fin,int fuel,vector<vector<ll>> &dp)\n{       // base case if fuel become -ve\n\t\tif(fuel<0)\n            return 0;\n        if(dp[str][fuel]!=-1)\n            return dp[str][fuel];\n        ll ans=0;\n        //if current index is final index\n        if(str==fin)\n           ans++;\n        // we traverse to every location from start\n        for(int i=0;i<loc.size();i++)\n        {   if(i!=str)\n               ans=((ans)%mod+count(loc,i,fin,fuel-abs(loc[str]-loc[i]),dp)%mod)%mod;\n        }\n        //store the result\n        dp[str][fuel]=(ans%mod);\n        return dp[str][fuel];\n    }\n    int countRoutes(vector<int>& locations, int start, int finish, int fuel) {\n        int n=locations.size();\n        //vector for storing the calculated result\n        vector<vector<ll>> dp(n,vector<ll>(fuel+1,-1));\n        return count(locations,start,finish,fuel,dp);\n    }\n\n};\n```
[]