I just got to know of @cache and @lru_cache in Python and it saves me so much of code
The constraints of this problem are really important. Also, this is simply a memoized solution, I\'m sure there must be a more elegant bitmasking dynamic progra
**The constraints of this problem are really important. Also, this is simply a memoized solution, I\'m sure there must be a more elegant bitmasking dynamic programming solution to this.**\n```\nclass Solution:\n    def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:\n        # Note why the constraint of the array integers being distinct is really important \n        # [1, 2, 3, 4, 3, ..] \n        # Possible answers are infinite [..., 2, ..], [..., 2, 4, ...], [..., 2, 4, 2, ..] ...\n        @cache \n        def getNumberOfPaths(node, target, rem_fuel):\n            if node == target and rem_fuel == 0:\n                return 1\n            if rem_fuel <= 0:\n                return 0\n            \n            ans = 0\n            for i in range(self.N):\n                if i == node:\n                    continue\n                ans += getNumberOfPaths(i, target, rem_fuel - abs(self.arr[node] - self.arr[i]))\n                ans  = int(ans % self.modulus)\n                \n            if node == target:\n                ans += 1\n            return ans \n        \n        self.arr = locations\n        self.N = len(locations)\n        self.modulus = 1e9 + 7\n        \n        return getNumberOfPaths(start, finish, fuel)\n```
[]