Java Bitmask
use bitmask to represent current works done. \nfor example, if current state = 101111 means second job is not done. \nTherefore, for the next state (111111), jo
use bitmask to represent current works done. \nfor example, if current state = 101111 means second job is not done. \nTherefore, for the next state (111111), job 2 is done and you will have :\n1. dp[111111][session+job2Time] = min(dp[111111][session+job2Time], dp[101111][session]) for currentJobsInTheSession+job2Time is smaller than sessionTime. \n\n2.  Otherwise, you will start a new session and it will be dp[111111][job2Time] = min(dp[111111][job2Time], dp[101111][session]+1)\n```\nclass Solution {\n    public int minSessions(int[] tasks, int sessionTime) {\n        Arrays.sort(tasks);\n        int res = tasks.length;\n        int n = tasks.length;\n        int[][] dp = new int[1<<n][sessionTime+1];\n        \n        for (int i = 0; i<(1<<n); i++) {\n            Arrays.fill(dp[i], 100);    \n        }\n        dp[0][0] = 1;\n        for (int i = 0; i<(1<<n); i++) {\n            for (int t = 0; t<n; t++) {\n                if (((1<<t) & i)==0) {\n                    int nextMask = i|(1<<t);\n                    for (int s = 0; s<sessionTime+1; s++) {\n                        if (s+tasks[t]<=sessionTime) {\n                            dp[nextMask][s+tasks[t]] = Math.min(dp[nextMask][s+tasks[t]], dp[i][s]);\n                        } else {\n                            dp[nextMask][tasks[t]] = Math.min(dp[nextMask][tasks[t]], dp[i][s]+1);\n                        }\n                    }\n                }\n            }\n        }\n        int len = dp.length;\n        for (int i = 0; i<sessionTime+1; i++) {\n            // System.out.println(dp[len-1][i]);\n            res = Math.min(res, dp[len-1][i]);\n        }\n        return res;\n    }\n    \n}\n```
[]