Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Microsoft - MaxEmployeeAttendence (R repititions - DP solution bitmask)
//g++ 7.4.0 // https://leetcode.com/discuss/interview-experience/1930164/Microsoft-or-SDE2-or-Hyderabad-or-April-2022-Reject #include <bits/stdc++.h> using namespace std; const int MAX_DAYS = 10; const int MAX_REPITITIONS = 10; const int MAX_EMPLOYEES = 10; int dp[MAX_DAYS][MAX_REPITITIONS][1 << MAX_EMPLOYEES]; vector<vector<int>> possible_attendants_at_day; int CountSetBits (int n) { int ans = 0; for (int j = 0; j < 30; j ++) { if (n&(1 << j)) ans ++; } return ans; } int MaxEmployeeAttendence (int current_day, int repititions_left, int employees_mask) { if (repititions_left == 0) return CountSetBits (employees_mask); if (current_day < 0) return 0; // There are no more days & we haven't organised the course for required `repititions`. int &result = dp[current_day][repititions_left][employees_mask]; if (result != -1) return result; result = 0; // take the current day int new_mask = employees_mask; for (int employee : possible_attendants_at_day[current_day]) { new_mask |= (1 << employee); } result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left-1, new_mask)); // don't take the current day result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left, employees_mask)); return result; } /* * availability[i] - list of days on which ith employee will be available to take the training. [0 <= availability[i][j] < D] * * total_days (D) - total number of days in which the training can be conducted. * * repititions (R) - number of times the training will be repeated in 'total_days' duration. * **/ int MaxEmployeeAttendence (vector<vector<int>>& availability, int total_days, int repititions) { memset(dp, -1, sizeof(dp)); possible_attendants_at_day.resize(total_days, {}); for (int employee = 0; employee < availability.size(); employee ++) { for (int day : availability[employee]) { possible_attendants_at_day [day].push_back(employee); } } return MaxEmployeeAttendence (total_days-1, repititions, 0); } int main() { vector<vector<int>> availability = { {0, 3, 9}, {4}, {1, 4}, {3, 2}, {3, 4}, {7} }; cout << MaxEmployeeAttendence (availability, 10, 3) << endl; return 0; }
run
|
edit
|
history
|
help
0
template
HashConPar
sd
ApelRefVal
const test
reverse array
Quadratic Equation
QuadRootPoint
good triplet
at.cpp