DP + Bitmasking | CPH
Page no. 103 of https://cses.fi/book/book.pdf  read from Permutations to subsets. \n\n\nclass Solution {\npublic:\n    int minSessions(vector<int>& tasks, int t
Page no. 103 of https://cses.fi/book/book.pdf  read from Permutations to subsets. \n\n```\nclass Solution {\npublic:\n    int minSessions(vector<int>& tasks, int t) {\n        int n=tasks.size();\n        vector<pair<int,int>>best(1<<n,{n+1,t+1});\n        // best[0]={1,0};\n        best[0]={0,t+1};\n        for(int i=1;i<(1<<n);++i){\n            // best[i]={n+1,0};\n            best[i]={n+1,t+1};\n            for(int j=0;j<n;++j){\n                if(i&(1<<j)){\n                    auto opt=best[i^(1<<j)];\n                    if(opt.second+tasks[j]<=t){\n                        opt.second+=tasks[j];\n                    }else{\n                        opt.first++;\n                        opt.second=tasks[j];\n                    }\n                    best[i]=min(best[i],opt);\n                }\n            }\n        }\n        return best[(1<<n)-1].first;\n    }\n};\n```\n\n[felixhuang07 ](https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1431820/C++-Bitmask-DP-with-Explanation-time:-O(n-*-2n)-space:-O(2n)/1065585) \n\n
['C']