思路:
dp。
实现:
1 class Solution 2 { 3 public: 4 int splitArray(vector<int>& nums, int m) 5 { 6 int n = nums.size(); 7 vector<int> sum(n + 1, 0); 8 for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nums[i - 1]; 9 vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MAX)); 10 for (int i = 1; i <= n; i++) dp[i][1] = sum[i]; 11 for (int i = 1; i <= n; i++) 12 { 13 for (int j = 2; j <= min(m, i); j++) 14 { 15 for (int k = 1; k < i; k++) 16 { 17 int tmp = sum[i] - sum[k]; 18 dp[i][j] = min(dp[i][j], max(tmp, dp[k][j - 1])); 19 } 20 } 21 } 22 return dp[n][m]; 23 } 24 };
原文地址:https://www.cnblogs.com/wangyiming/p/9141403.html
时间: 2024-10-24 15:17:59