You are viewing a single comment's thread. Return to all comments →
A small recursive solution:
unordered_map<int, int> _hashMap; int GetMaxWorkshops(Available_Workshops* ptr, int cur_time) { if (_hashMap.count(cur_time) != 0) return _hashMap[cur_time]; int maxCount = 0; int count = 0; for (int i = 0; i < (*ptr).n; ++i) { count = 0; Workshop ws = (*ptr).allWorkshops[i]; if (ws.startTime >= cur_time) { count += GetMaxWorkshops(ptr, ws.endTime) + 1; } maxCount = max(count, maxCount); } _hashMap[cur_time] = maxCount; return maxCount; } int CalculateMaxWorkshops(Available_Workshops* ptr) { _hashMap.clear(); return GetMaxWorkshops(ptr, 0); }
Seems like cookies are disabled on this browser, please enable them to open this website
Attending Workshops
You are viewing a single comment's thread. Return to all comments →
A small recursive solution: