[C++] DP+Bitmasking
\n/*\n   Kind of Problem where we have the option to Pick now or Pick later but we definatley have to pick all items.\n   We are using dp with bitmasking here w
```\n/*\n   Kind of Problem where we have the option to Pick now or Pick later but we definatley have to pick all items.\n   We are using dp with bitmasking here where a ith bit in mask represents that element isPicked or not.\n   if 1 that means picked if 0 means not picked Yet.\n   We will do memoization to save time and store the result on two changing states mask(isTaken) and currTime\n   The constraints given that array is of size 14 atMax and sessionTime is 15 atMax so that means we will only need mask of size 1<<15\n   and second column is made of size 16 (1 grater than specified size of sessionTime)\n   \n   Approach : We are taking a mask intially and picking elements and setting ith bit of mask to represent we have picked and currTime should be atMax <= SessionTime\n              so we are adding tasks values in this variable(currentTime) once it exceeds the sessionTime we will break recursion, we also have the option to not pick\n              for that we are also setting the ith bit because it will also be picked (we are including this but including in next work session) and adding 1 that represents \n              that we have created 1 more session by sending this element to be picked in next session and as we have created the next session so currentTime will be zero for this\n              these recursion calls will give us work sessions which are created so we selecting minimum as asked in question and caching it with dp and returning min number of work \n              sessions.\n              we have One condition (isTaken == (1<<N)-1) that represents that we picked all elements (because Nth bit will be set only we reached last element of array and we subtracted 1\n              beacuse we are accesding bits by N in number 1 which has already a set bit in simple terms to counter the effect of 1 we reduced this 1) \n              will return 1 (as consider a case) - Input: tasks = [1,2,3,4,5], sessionTime = 15, in this all tasks will be counted in single work session so includeInNext will never be counted\n              hence we never added 1 in whole program to represent that this is a session so for that we returned 1 in condition (isTaken == (1<<N)-1)\n*/\nclass Solution {\npublic:\n    int dp[1<<15][16];\n    int Sessions(vector<int> &tasks, int sessionTime, int isTaken, int currentTime, int N){\n        //exceding the boundraies\n        if(currentTime>sessionTime)\n            return INT_MAX;\n        //checking if all elements are selected\n        if(isTaken == (1<<N)-1)\n            return 1;\n        //returning cached results if they are already calcultated\n        if(dp[isTaken][currentTime] != -1)\n            return dp[isTaken][currentTime];\n        int ans = INT_MAX;\n        for(int i=0; i<N; i++){\n            //Means this index element is not picked yet\n            if(!(isTaken&(1<<i))){\n                //include in current work session so for that we added taks[i] in currentTime\n                int includeNow = Sessions(tasks, sessionTime, isTaken|(1<<i), currentTime+tasks[i], N);\n                //creating a new work session\n                int includeInNext = 1 + Sessions(tasks, sessionTime, isTaken|(1<<i), 0+tasks[i], N);\n                ans = min({ans, includeNow, includeInNext});\n            }\n        }\n        dp[isTaken][currentTime] = ans;\n        return dp[isTaken][currentTime];\n    }\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        memset(dp, -1, sizeof(dp));\n        return Sessions(tasks, sessionTime, 0, 0, tasks.size());\n    }\n};\n```
[]