leetcode410 Split Array Largest Sum
思路:
dp。
实现:
class Solution
{
public:
int splitArray(vector<int>& nums, int m)
{
int n = nums.size();
vector<int> sum(n + , );
for (int i = ; i <= n; i++) sum[i] = sum[i - ] + nums[i - ];
vector<vector<int>> dp(n + , vector<int>(m + , INT_MAX));
for (int i = ; i <= n; i++) dp[i][] = sum[i];
for (int i = ; i <= n; i++)
{
for (int j = ; j <= min(m, i); j++)
{
for (int k = ; k < i; k++)
{
int tmp = sum[i] - sum[k];
dp[i][j] = min(dp[i][j], max(tmp, dp[k][j - ]));
}
}
}
return dp[n][m];
}
};
leetcode410 Split Array Largest Sum的更多相关文章
- [Swift]LeetCode410. 分割数组的最大值 | Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- [LeetCode] Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- Leetcode: Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- 动态规划——Split Array Largest Sum
题意大概就是,给定一个包含非负整数的序列nums以及一个整数m,要求把序列nums分成m份,并且要让这m个子序列各自的和的最大值最小(minimize the largest sum among th ...
- Split Array Largest Sum LT410
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- 410. Split Array Largest Sum 把数组划分为m组,怎样使最大和最小
[抄题]: Given an array which consists of non-negative integers and an integer m, you can split the arr ...
- [LeetCode] 410. Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- 【leetcode】410. Split Array Largest Sum
题目如下: Given an array which consists of non-negative integers and an integer m, you can split the arr ...
随机推荐
- YTU 2577: 小数计算——结构体
2577: 小数计算--结构体 时间限制: 1 Sec 内存限制: 128 MB 提交: 978 解决: 647 题目描述 小数可以看成是一个点和两个数组成的,因此可以定义成一个小数的结构体,现在 ...
- jquery 获取radio被选中的值
<html> <head> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"& ...
- MD5Util1
package com.cc.hkjc.util; import java.math.BigInteger;import java.security.MessageDigest;import java ...
- [Selenium] Android 中旋转屏幕,触摸,滚动
package com.learingselenium.android; import junit.framework.TestCase import org.openqa.selenium.Rota ...
- 【POJ 1061】 青蛙的约会
[题目链接] 点击打开链接 [算法] 列出同余方程,然后用exgcd求解 [代码] #include <algorithm> #include <bitset> #includ ...
- ng 表单提交验证
http://www.runoob.com/try/try.php?filename=try_ng_validate
- bzoj4555
ntt+cdq分治 原来zwh出的cf是斯特林 第二类斯特林数的定义是S(i,j)表示将i个物品分到j个无序集合的方案数,那么这道题中S(i,j)*j!*2^j是指将i个物品分到j个有序集合中并且每个 ...
- EasyUI 表格点击右键添加或刷新 绑定右键菜单
例1 在HTML页面中设置一个隐藏的菜单(前提是已经使用封装的Easyui) 代码: <div id="contextMenu_jygl" class="easyu ...
- hibernate的基础学习--一对多关联
基本的用户和部门类,只有uuid和名称,没有其余字段. 配置文件 部门: <?xml version="1.0" encoding="utf-8" ?&g ...
- leetCode :103. Binary Tree Zigzag Level Order Traversal (swift) 二叉树Z字形层次遍历
// 103. Binary Tree Zigzag Level Order Traversal // https://leetcode.com/problems/binary-tree-zigzag ...