leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1335.cpp (801B)


0 class Solution { 1 static uint dp[11][301]; 2 3 public: 4 Solution() { memset(dp, 0xFF, sizeof(dp)); } 5 int minDifficulty(const vector<int> &jobDifficulty, int d, int idx = 0) const { 6 if (d == 0) return (idx != jobDifficulty.size()) * UINT_MAX; 7 if (jobDifficulty.size() - idx < d) return -1; 8 if (dp[d][idx] != UINT_MAX) return dp[d][idx]; 9 uint res = UINT_MAX, maxi = 0; 10 for (int i = idx; i < jobDifficulty.size(); i++) { 11 maxi = max(maxi, (uint)jobDifficulty[i]); 12 const int next = minDifficulty(jobDifficulty, d - 1, i + 1); 13 if (next == UINT_MAX) continue; 14 res = min(res, maxi + next); 15 } 16 dp[d][idx] = res != UINT_MAX ? res : res - 1; 17 return res; 18 } 19 }; 20 21 uint Solution::dp[11][301];