C++ | Recursion with Memoization | DP
\n\n# Code\n\nclass Solution {\npublic:\n    int dp[105][205];\n    int mod= 1000000007;\n    int visitCity(int city, int fuel, vector<int>& locations, int fini
\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[105][205];\n    int mod= 1000000007;\n    int visitCity(int city, int fuel, vector<int>& locations, int finish, int n)\n    {\n        if(fuel<0) return 0;\n        if(dp[city][fuel]!=-1)\n        return dp[city][fuel];\n        int count=0;\n        \n        if(city==finish)\n        count ++;\n        for(int i=0; i<n;i++)\n        {\n            if(i!=city)\n            {\n                int fuelUsed= locations[i]>locations[city]?locations[i] -locations[city]: locations[city]-locations[i];\n                count+= visitCity(i, fuel-fuelUsed, locations, finish, n);\n                count%= mod;\n            }\n        }\n        return dp[city][fuel]= count%mod;\n        \n    }\n    int countRoutes(vector<int>& locations, int start, int finish, int fuel) \n    {\n        int n= locations.size();\n        memset(dp, -1, sizeof(dp));\n        int count =visitCity(start, fuel, locations, finish, n);\n        return count;\n    }\n};\n```
['C++']