Simple C++ Backtracking + DP solution with comments
Basic Idea\nThe idea here is to use Backtracking + DP in order to solve this problem under the given constraints.\n\nIntution:\nThe basic intution we are going 
**Basic Idea**\nThe idea here is to use **Backtracking + DP** in order to solve this problem under the given constraints.\n\n**Intution:**\nThe basic intution we are going to use is that every element in the tasks array can either be included in its own separate session or in any one of the existing sessions. Whatever be the minimum of these two will be our answer.\nWe\'ll use a arr vector, where length of arr will denote the number of sessions we currently have and arr[i] will denote the number of hours we have worked in that ith session.\n\n**CODE:**\n```\n\tvector<int> arr;\n\t//unordered map for our dp table\n    unordered_map<string,int> dp;\n    \n\t//function to make key to be used in dp map\n\t// note: here we first sort copy array to reduce the repeated states\n    string makeKey(vector<int> &arr,int pos)\n    {\n        string str = to_string(pos) + \'$\';\n        vector<int> copy = arr;\n        sort(copy.begin(),copy.end());\n        for(auto val : copy) str += to_string(val) + \'$\';\n        \n        return str;\n    }\n    \n    int recur(vector<int> &tasks,int sessionTime,int pos)\n    {\n\t\t//if all tasks are finished , we return 0 indicating no more session is required\n        if(pos >= tasks.size()) return 0;\n        \n\t\t//getting key from the function above\n        string key = makeKey(arr,pos);\n        \n\t\t//if the key exists in our map, we\'ll simpy use it\'s value else we\'ll continue\n        if(dp.find(key) != dp.end()) return dp[key];\n        \n\t\t//Case 1: we make a separate session for our current task\n\t\t//             and solve for rest of the array using backtracking\n        arr.push_back(tasks[pos]);\n        int ans = 1 + recur(tasks,sessionTime,pos+1);\n        arr.pop_back();\n        \n\t\t//Case 2: we try to include the current session in any one of the previous sessions\n\t\t//            and try to solve for rest of array using backtracking, keeping track of the minm\n\t\t//            value and storing it in our ans variable\n        for(int i=0;i<arr.size();i++)\n        {\n            if(arr[i] + tasks[pos] <= sessionTime)\n            {\n                arr[i] += tasks[pos];\n                ans = min(ans,recur(tasks,sessionTime,pos+1));\n                arr[i] -= tasks[pos];\n            }\n        }\n        \n\t\t//storing the ans for the current key and returning the ans calculated \n        return dp[key] = ans;\n    }\n\t\n\tint minSessions(vector<int>& tasks, int sessionTime) {\n        return recur(tasks,sessionTime,0);\n    }\n```
['Dynamic Programming', 'C']