C++ | Explanation (Recursion + Memo + Bitmask)
We will keep adding to current untill task[pos]+cur <=SessionTime, ans remains same since we are not starting new session.\nIf cur+task[pos]>SessionTime, then w
We will keep adding to current untill task[pos]+cur <=SessionTime, ans remains same since we are not starting new session.\nIf cur+task[pos]>SessionTime, then we will start new session,and add 1 to ans since we are starting new session.\nEverytime we start new session , we should add 1 to ans.\n\nHere, in dp[mask][cur], mask stands for all task, that has been completed, and cur stands for elapsed time for current session.\n\n\nBonus point: Bitmasking works fine only for smaller input , for n<=16. Beacuse we have to iterate through every possible subset of size n. Number of subsets is 2^n, if n is the number of elements, and 2^16 is around 6 * 10^4\nSo, next time when you see n<=16. Go for approach with the Bitmask.\n```\nclass Solution {\npublic:\n    int dp[1<<14][17];\n    int INF=1e8;\n    int m;\n    int solve(int mask,int cur,vector<int> &t,int s)\n    {\n        if(mask==(1<<m)-1)      // If all the task is included mask becomes 11111....(m times) which (2^m -1) =(1<<m)-1\n            return 0;\n        else if(dp[mask][cur]!=-1)\n            return dp[mask][cur];\n        int ans=INF;\n        for(int i=0;i<t.size();i++)\n        {\n            if(mask&(1<<i))    // If already included in any session, we just continue.\n                continue;\n            else if(cur+t[i]<=s)\n                ans=min(ans,solve(mask|(1<<i),cur+t[i],t,s));  //Add to current session\n            else\n                ans=min(ans,solve(mask|(1<<i),t[i],t,s)+1);    // Start new session\n        }\n        return dp[mask][cur]=ans;\n    }\n    int minSessions(vector<int>& t, int s) {\n        memset(dp,-1,sizeof dp);\n        m=t.size();\n        return solve(0,16,t,s);\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Bitmask']