Python 1-liner. Recursion. DP. Functional programming.
Approach\nTL;DR, Similar to Editorial solution but short and functional.\n\n# Complexity\n- Time complexity: O(n^2 * m)\n\n- Space complexity: O(n * m)\n\nwhere
# Approach\nTL;DR, Similar to [Editorial solution](https://leetcode.com/problems/count-all-possible-routes/editorial/) but short and functional.\n\n# Complexity\n- Time complexity: $$O(n^2 * m)$$\n\n- Space complexity: $$O(n * m)$$\n\nwhere,\n`n is number of cities, i.e length of locations`,\n`m is amount of fuel`.\n\n# Code\nFew liner:\n```python\nclass Solution:\n    def countRoutes(self, locations: list[int], start: int, finish: int, fuel: int) -> int:\n        @cache\n        def routes(s: int, f: int) -> int:\n            return ((s == finish) + sum(routes(e, f - d) for e in range(len(locations)) if s != e and (d := abs(locations[s] - locations[e])) <= f)) % 1_000_000_007\n        \n        return routes(start, fuel)\n\n\n```\n\n1-liner:\n```python\nclass Solution:\n    def countRoutes(self, locations: list[int], start: int, finish: int, fuel: int) -> int:\n        return (routes := cache(lambda s, f: ((s == finish) + sum(routes(e, f - d) for e in range(len(locations)) if s != e and (d := abs(locations[s] - locations[e])) <= f)) % 1_000_000_007))(start, fuel)\n\n\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3']