[C++] Dynamic Programming with bit-masking (commented)
\nclass Solution\n{\n  public:\n    int n, k;\n    vector<int> a;\n    int dp[(1 << 14) + 5][16];\n    int find(int mask, int left)\n    {\n    \t// mask = to s
```\nclass Solution\n{\n  public:\n    int n, k;\n    vector<int> a;\n    int dp[(1 << 14) + 5][16];\n    int find(int mask, int left)\n    {\n    \t// mask = to store the state of already selected items\n    \t// left = how much sessionTime is still left to consume\n        if (mask == (1 << n) - 1)\n            return 0;\n        int &mn = dp[mask][left];\n        // memoization\n        if (mn != -1)\n            return mn;\n        mn = 1e9;\n        for (int i = 0; i < n; i++)\n        {\n        \t// if ith item is not selected in mask the select it\n            if (((mask >> i) & 1) == 0)\n            {\n            \t// if sessionTime is still left to consume the simply subtract from it \n            \t// and set the ith item in the mask\n                if (left - a[i] >= 0)\n                    mn = min({mn, find((mask | (1 << i)), left - a[i])});\n                // since every item is greater tha sessionTime i.e. (a[i]>=k), then\n                // consume it from fresh sessionTime and increse the session by 1. \n                mn = min(mn, 1 + find((mask | (1 << i)), k - a[i]));\n            }\n        }\n        return mn;\n    }\n    int minSessions(vector<int> &tasks, int sessionTime)\n    {\n        a = tasks;\n        n = size(a), k = sessionTime;\n        for (auto &x : dp)\n            for (auto &y : x)\n                y = -1;\n        return find(0, k) + 1;\n    }\n};\n```
[]