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