Dynamic Programming
Intuition\nDynamic programming\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nDynamic Programming\n Describe your approach to solv
# Intuition\nDynamic programming\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nDynamic Programming\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n*m) n=sizeOfArray m=fuel\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n*m) n=100,m=200\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int p=1e9+7;\n    int dp[101][201];\n    long long solve(vector<int>&vec,int i, int f,int fuel){\n        int n=vec.size();\n        long long ans=0;\n        if(dp[i][fuel]!=-1) return dp[i][fuel];\n        if(vec[i]==f) ans++;\n        if(fuel<0) return 0;\n        for(int j=0;j<n;j++){\n            if(j!=i){\n                if(fuel>=abs(vec[j]-vec[i])) ans=(ans+solve(vec,j,f,fuel-abs(vec[j]-vec[i])))%p;\n            }\n        }\n        return dp[i][fuel]=ans%p;\n    }\n    int countRoutes(vector<int>& locations, int start, int finish, int fuel) {\n        // int s=locations[start],e=locations[finish];\n        // sort(locations.begin(),locations.end());\n        memset(dp,-1,sizeof(dp));\n        int ans=solve(locations,start,locations[finish],fuel);\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C++']