[Java] Bitmask DP, O(N2^N)
Let us let a bitmask represent the available tasks and the unavaliable tasks where a 1 bit represents that a task is still available and 0 bit represents a task
Let us let a bitmask represent the available tasks and the unavaliable tasks where a `1` bit represents that a task is still available and `0` bit represents a task that is unavailable. \n\nThen, we can let `dp[bitmask]` represent the minimum sessions required to fullfill all the tasks of that bitmask. \n\nTo solve for `dp[bitmask]`, we can iterate through all submasks, (subsets of the avaliable masks), and let all the available tasks of that submask be one session. We need to check first if that is a valid one session by summing up the task time and making sure its less than sessionTime. We can then recurse on `dp[bitmask ^ submask`].\n\n\n```\nclass Solution {\n    int res = Integer.MAX_VALUE;\n    Integer[] dp;\n    \n    // 1 == unused, 0 == used\n    public int dp(int[] tasks, int sessionTime, int mask){\n        if(mask == 0) return 0;\n        if(dp[mask] != null) return dp[mask];\n        int res = Integer.MAX_VALUE;\n        int n = tasks.length;\n        for (int submask = mask;; submask = (submask - 1) & mask) {\n            if (submask == 0)\n                break;\n            int totalTime = 0;\n            for(int i=0; i<n; i++){\n                if((submask & (1 << i)) != 0){\n                    totalTime += tasks[i];\n                }\n            }\n            if(totalTime <= sessionTime){\n                int next_mask = mask ^ submask;\n                res = Math.min(res, 1 + dp(tasks, sessionTime, next_mask));\n            }\n        }\n        return dp[mask] = res;\n    }\n    \n    public int minSessions(int[] tasks, int sessionTime) {\n        int n = tasks.length;\n        dp = new Integer[(1 << n)+1];\n        return dp(tasks, sessionTime, (1 << n) - 1);\n    }\n}\n```
[]