[C++] Binary Search + DFS + Memo
If x is the minimum number  of work sessions to finish the tasks, then any value of work sessions larger than x would also be enough to finish the tasks. Thus, 
If x is the minimum number  of work sessions to finish the tasks, then any value of work sessions larger than x would also be enough to finish the tasks. Thus, we can apply binary search to this question.\n\nThe initial `left` can be 0, and `right` is the size of the tasks (why?).\n\nThe first guess could be `mid = left + (right - left) / 2`.\n\nThen the question becomes: if we have `mid` work sesssions (each has sessionTime hours), can we finsih all the tasks?\n\nSo it becomes a multi-knapsack problem.\n\nThe good news is that the numbe rof tasks and sessionTime are very small, so we can memorize all the possible states. For example, the bits of an integer can be used to record whether each tasks has been finished or not.\n\nSee the code below:\n\n\n```\nclass Solution {\npublic:\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        int n = tasks.size(), left = 0, right = n;\n        sort(tasks.begin(), tasks.end(), greater());\n        vector<vector<vector<int>>> memo(1<<n, vector<vector<int>>(n+1, vector<int>(sessionTime+1, -1)));\n        while(left < right) {\n            int mid = left + (right - left) / 2;\n            if(!valid(tasks, 0, 0, sessionTime, mid, memo)) left = mid + 1;\n            else right = mid;\n           // cout<<mid<<" "<<left<<" "<<right<<endl;\n        }\n        return left;\n    }\nprivate:\n    bool valid(vector<int>& ts, int state, int sum, int& tm, int mid, vector<vector<vector<int>>>& memo) {\n        int n = ts.size();\n        if(state + 1 == (1<<n)) return sum > 0 ? mid > 0 : mid >= 0;\n        if(mid<=0) return false;\n        if(memo[state][mid][sum] != -1) return memo[state][mid][sum];\n        for(int i=0; i<n; ++i) {\n            if((state>>i) & 1) continue;\n            if(tm < sum + ts[i]) continue;\n            if(valid(ts, state | (1<<i), sum + ts[i], tm, mid, memo)) return memo[state][mid][sum] = 1;\n        }\n        return memo[state][mid][sum] = valid(ts, state, 0, tm, mid - 1, memo);\n    }\n};\n```
[]