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 ...
随机推荐
- ActiveMQ 入门使用p2p模型-主动消费
生产者 package clc.active; import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XmlVisitor; import ...
- MYSQL进阶学习笔记八:MySQL MyISAM的表锁!(视频序号:进阶_18-20)
知识点九:MySQL MyISAM表锁(共享读锁)(18) 为什么会有锁: 打个比方,我们到淘宝买一件商品,商品只有一件库存,这时候如果还有另外一个人也在买,那么如何解决是你买到还是另一个人买到的问题 ...
- 第三届蓝桥杯C++B组省赛
1.微生物增值 2.古堡算式 3.海盗比酒量 4.奇怪的比赛 5.方阵旋转 6.大数乘法 7.放棋子 8.密码发生器 9.夺冠概率 10.取球博弈
- No tests found with test runner 'JUnit 3'
报异常:No tests found with test runner 'JUnit 3' 解决方案: 主要因为你当前建的JUnit类是3的版本,将该类备份,重新创建一个类. 1.右键目录New--O ...
- hdu(1007) 最近点对 分治法
最近点对一般想到枚举 ,一一枚举时间复杂度为n^2:枚举时候一些操作是多余的,有了分治算法的思想 ,把一些问题分个击破,再回到整体. 题目链接 以这道题为例,我们可以把他按照x轴的升序分成多个子区域 ...
- linux静默安装Oracle 11g
./runInstaller -silent -force -responseFile /home/oracle/software/database/response/orcl_install.rsp ...
- codeforces 690D1 D1. The Wall (easy)(dfs)
题目链接: D1. The Wall (easy) time limit per test 0.5 seconds memory limit per test 256 megabytes input ...
- I.MX6 boot from Micro SD
/***************************************************************************** * I.MX6 boot from Mic ...
- javascript之存储数据-cookie,localStorage,sessionStorage
cookie: 存储一些简单的数据,以文本形式放到本地,大小4kb 存储:document.cookie='name=value' 取值:document.cookie(字符串) 期限:expires ...
- noip2010引水入城
https://www.zybuluo.com/ysner/note/1334997 这道题fst了 题面 戳我 解析 我一开始的想法是,按照高度给第一行排序,然后贪心地选取目前到不了的,高度最高的第 ...