leetcode410 Split Array Largest Sum

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode410 Split Array Largest Sum相关的知识,希望对你有一定的参考价值。

思路:

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 };

 

以上是关于leetcode410 Split Array Largest Sum的主要内容,如果未能解决你的问题,请参考以下文章

leetcode 410. Split Array Largest Sum

leetcode410 Split Array Largest Sum

410. Split Array Largest Sum

410. Split Array Largest Sum

410. Split Array Largest Sum

410. Split Array Largest Sum