C++ || TSP variation ||  simple explaination
variation of "Travelling salesman Problem"\n     \n            \n    //  we will  choose a task from the set of  un-completed task using bit-mask.\n    //  if t
variation of "Travelling salesman Problem"\n     \n            \n    //  we will  choose a task from the set of  un-completed task using bit-mask.\n    //  if time required to do this task + time exhuasted in prev task is less than or equal to  sessionTime then we can do this task in same session .\n    // otherwise, we have to start new session.\n    \n    \n    \n    \n    int target;\n    int  fun(vector<int>&tasks,int mask,int curr_sum,int&T,vector<vector<int>>&dp){\n         int n=tasks.size();\n         if(mask==target){\n             return  1;\n         }\n        \n         // if already visited the current state then we will return from here only\n         if(dp[mask][curr_sum]!=-1)\n            return dp[mask][curr_sum];\n        \n        int ans= INT_MAX;\n        int new_mask;\n        \n        for(int i=0;i<n;i++){\n             if(mask&(1<<i))  continue;\n            \n            // if task[i]  has not been done yet then.....\n             new_mask=mask|(1<<i);\n             if((curr_sum+tasks[i])>T){\n                   ans=min(ans,1+fun(tasks,new_mask,tasks[i],T,dp)); \n             }\n             else\n                  ans=min(ans,fun(tasks,new_mask,curr_sum+tasks[i],T,dp)); \n             \n         }\n        \n        dp[mask][curr_sum]=ans;\n        return dp[mask][curr_sum];\n        \n    }\n    int minSessions(vector<int>& tasks, int T) {\n         int n=tasks.size();\n         target=(1<<n)-1;   \n         int sum=0;\n         for(auto& num:tasks){\n             sum+=num;\n         }\n        \n         \n         vector<vector<int>>dp((1<<n)+5,vector<int>(sum+1,-1));\n         return fun(tasks,0,0,T,dp);\n          \n    }\n};
[]