-
[LeetCode] 1043. Partition Array for Maximum SumLeetCode 2021. 10. 18. 18:07728x90
https://leetcode.com/problems/partition-array-for-maximum-sum/
Partition Array for Maximum Sum - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Partition Array for Maximum Sum

전체 풀이 코드
class Solution { public: int maxSumAfterPartitioning(vector<int>& arr, int k) { int dp[501] = {0}; dp[0] = 0; for (int i=1; i<=arr.size(); i++) { int M = 0; for (int j=1; j<=k && i>=j; j++) { M = max(M, arr[i-j]); dp[i] = max(dp[i], dp[i-j] + M*j); } } return dp[arr.size()]; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 496. Next Greater Element I (0) 2021.10.19 [LeetCode] 1779. Find Nearest Point That Has the Same X or Y Coordinate (0) 2021.10.19 [LeetCode] 454. 4Sum II (0) 2021.10.18 [LeetCode] 18. 4Sum (0) 2021.10.18 [LeetCode] 16. 3Sum Closest (0) 2021.10.18