(DP + bit masking) Similar to travelling salesman problem with slight modification
This problem can be easily solved using dynamic programming and bitmasking\n\nHere,  the ith bit in mask is 1 if the ith task has been completed otherwise it is
This problem can be easily solved using dynamic programming and bitmasking\n\nHere,  the ith bit in mask is 1 if the ith task has been completed otherwise it is 0\nwhen all the tasks are done, the value of mask will be equal to the value of \'done\'\n\n```\nclass Solution {\npublic:\n    int solve(vector<int> &tasks,int n,vector<vector<int> > &dp,int sessionTime,int cur_session,int mask,int done) {\n        if(mask==done) {\n            return 0;\n        }\n\t\t// if the value was calculated earlier, we return that value and save computation time\n        if(dp[mask][cur_session]!=-1) {\n            return dp[mask][cur_session];\n        }\n        int ans = INT_MAX; // let\'s assume INT_MAX sessions are required\n        for(int i=0;i<n;i++) {\n            if(((mask>>i)&1)==0) { // if the task has not been completed\n\t\t\t\t//cur_session stored the time used in the current session\n                if(cur_session+tasks[i] <= sessionTime) { // if the task can be completed in current session\n                    int tmp = mask;\n                    mask = (mask|(1<<i)); // we mark that the task has been completed\n                    ans = min(ans,solve(tasks,n,dp,sessionTime,cur_session+tasks[i],mask,done));\n                    mask = tmp;\n                }\n            }\n        }\n        if(ans==INT_MAX) { // if no task can be completed in the current session, start a new session\n            return dp[mask][cur_session] = 1 + solve(tasks,n,dp,sessionTime,0,mask,done);\n        }\n\t\t// store and return answer\n        return dp[mask][cur_session] = ans;\n    }\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        int n = tasks.size();\n        int done = 0;\n        for(int i=0;i<n;i++) {\n            done = (done|(1<<i));\n        }\n        vector<vector<int> > dp((1<<n),vector<int>(sessionTime+1,-1));\n        return 1+solve(tasks,n,dp,sessionTime,0,0,done);\n    }\n};\n```\n\nTime complexity : ```(2^n)*n```\nspace compexity:``` (2^n)*sessionTime```
[]