[Python] recursion + tuple memoization, no bitmask, simple 64ms
I thought some of the other python recursion answers were not that intuitive. Here we simply try each possibility and cache what we\'ve done so far so no repeti
I thought some of the other python recursion answers were not that intuitive. Here we simply try each possibility and cache what we\'ve done so far so no repetition. We take advantage of the tuple data structure which can be cached. The parameter x represents remaining sessiontime for this session. We reset it (plus add to session count) if we can\'t fit anymore tasks in it. \n\n```\nclass Solution:\n    def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n        tasks = sorted(tasks)\n\n        @lru_cache(None)\n        def recur_fn(x,tasks):\n            if len(tasks) == 0:\n                return 1\n            ans = 0\n            result = []\n            if tasks[0] > x:\n                ans += 1  #on to the new session as can\'t fit anything in \n                x = sessionTime #resets remaining session time to full session \n            for i,val in enumerate(tasks):\n                if val <= x:\n                    result.append(recur_fn(x-val,tasks[0:i] + tasks[i+1:]))\n                else:\n                    break\n            return ans + min(result)\n        \n        return recur_fn(sessionTime,tuple(tasks))
['Recursion', 'Memoization', 'Python3']