当前位置: 首页 > news >正文

哪个购物平台质量好价格合适浙江seo外包

哪个购物平台质量好价格合适,浙江seo外包,成品网站w灬 源码1688网页,python做网站视频教程hard:https://leetcode.cn/problems/split-array-largest-sum/ 给定一个非负整数数组 nums 和一个整数 m ,你需要将这个数组分成 m 个非空的连续子数组。 设计一个算法使得这 m 个子数组各自和的最大值最小。 示例 1:输入:nums [7,2,5,1…
  • hard:https://leetcode.cn/problems/split-array-largest-sum/

  • 给定一个非负整数数组 nums 和一个整数 m ,你需要将这个数组分成 m 个非空的连续子数组

  • 设计一个算法使得这 m 个子数组各自和最大值最小

示例 1:输入:nums = [7,2,5,10,8], m = 2
输出:18
解释:
一共有四种方法将 nums 分割为 2 个子数组。 
其中最好的方式是将其分为 [7,2,5][10,8] 。
因为此时这两个子数组各自的和的最大值为18,在所有情况中最小。
示例 2:输入:nums = [1,2,3,4,5], m = 2
输出:9
示例 3:输入:nums = [1,4,4], m = 3
输出:4提示:1 <= nums.length <= 1000
0 <= nums[i] <= 106
1 <= m <= min(50, nums.length)

题解

  • 令 dp[i][j]表示将数组的前 i 个数分割为 j 组所能得到的最大连续子数组和的最小值

  • 确定装填转移方程(考虑dp[i][j]需要遍历所有分为j-1组的情况):
    d p [ i ] [ j ] = m i n k = 0 i − 1 { m a x ( d p [ k ] [ j − 1 ] , s u b ( k + 1 , i ) ) } = m i n k = 0 i − 1 { m a x ( d p [ k ] [ j − 1 ] , s u m ( n u m s [ k + 1 … j ] ) ) } dp[i][j]= min_{k=0}^{ i−1} \{max(dp[k][j−1],sub(k+1,i))\}\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ = min_{k=0}^{ i−1} \{max(dp[k][j−1],sum(nums[k+1…j]))\} dp[i][j]=mink=0i1{max(dp[k][j1],sub(k+1,i))}                               =mink=0i1{max(dp[k][j1],sum(nums[k+1j]))}

  • 确定边界:填表法

        nums = [7,2,5,10,8],m=2。

i\j012
0无法分为0组INT_MAXINT_MAX
1无法分为0组71个数无法分为2组(i<j)
2无法分为0组7+2 m i n ( [ 7 ] , [ 2 ] ) = 2 min([7],[2])=2 min([7],[2])=2
3无法分为0组7+2+5 m i n [ m a x ( d p [ 1 ] [ 1 ] , [ 2 , 5 ] ) m a x ( d p [ 2 ] [ 1 ] , [ 5 ] ) ] = 7 min\begin{bmatrix} max(dp[1][1],[2,5]) \\ max(dp[2][1],[5]) \end{bmatrix}=7 min[max(dp[1][1],[2,5])max(dp[2][1],[5])]=7
4无法分为0组7+2+5+10 m i n [ m a x ( d p [ 1 ] [ 1 ] , [ 2 , 5 , 10 ] ) m a x ( d p [ 2 ] [ 1 ] , [ 5 , 10 ] ) m a x ( d p [ 3 ] [ 1 ] , [ 10 ] ) ] = 14 min\begin{bmatrix} max(dp[1][1],[2,5,10]) \\ max(dp[2][1],[5,10]) \\ max(dp[3][1],[10]) \end{bmatrix}=14 min max(dp[1][1],[2,5,10])max(dp[2][1],[5,10])max(dp[3][1],[10]) =14 前*个数分为一组和剩下的部分
5无法分为0组7+2+5+10+8 m i n [ m a x ( d p [ 1 ] [ 1 ] , [ 2 , 5 , 10 , 8 ] ) m a x ( d p [ 2 ] [ 1 ] , [ 5 , 10 , 8 ] ) m a x ( d p [ 3 ] [ 1 ] , [ 10 , 8 ] ) m a x ( d p [ 4 ] [ 1 ] , [ 8 ] ) ] = 18 min\begin{bmatrix} max(dp[1][1],[2,5,10,8]) \\ max(dp[2][1],[5,10,8]) \\ max(dp[3][1],[10,8])\\ max(dp[4][1],[8]) \end{bmatrix}=18 min max(dp[1][1],[2,5,10,8])max(dp[2][1],[5,10,8])max(dp[3][1],[10,8])max(dp[4][1],[8]) =18

code

class Solution {
public:int splitArray(vector<int>& nums, int m) {int n = nums.size();vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, LLONG_MAX));vector<long long> sub(n + 1, 0);for (int i = 0; i < n; i++) {sub[i + 1] = sub[i] + nums[i];}dp[0][0] = 0;for (int i = 1; i <= n; i++) {for (int j = 1; j <= min(i, m); j++) {for (int k = 0; k < i; k++) {dp[i][j] = min(dp[i][j], max(dp[k][j - 1], sub[i] - sub[k]));}}}return (int)dp[n][m];}
};

文章转载自:
http://intelligentize.gtqx.cn
http://improviser.gtqx.cn
http://bilievable.gtqx.cn
http://felicitate.gtqx.cn
http://deintegro.gtqx.cn
http://drawling.gtqx.cn
http://councillor.gtqx.cn
http://kcmg.gtqx.cn
http://cathodograph.gtqx.cn
http://mattin.gtqx.cn
http://truthlessness.gtqx.cn
http://envoi.gtqx.cn
http://demophobic.gtqx.cn
http://depauperation.gtqx.cn
http://underslept.gtqx.cn
http://newyorican.gtqx.cn
http://sundeck.gtqx.cn
http://smirch.gtqx.cn
http://midlothian.gtqx.cn
http://glassware.gtqx.cn
http://monadnock.gtqx.cn
http://redball.gtqx.cn
http://salmanazar.gtqx.cn
http://cerated.gtqx.cn
http://foist.gtqx.cn
http://vasodilatation.gtqx.cn
http://interjectory.gtqx.cn
http://caste.gtqx.cn
http://luculent.gtqx.cn
http://ethynyl.gtqx.cn
http://astraddle.gtqx.cn
http://brightsome.gtqx.cn
http://maninke.gtqx.cn
http://pax.gtqx.cn
http://mostaccioli.gtqx.cn
http://flaccid.gtqx.cn
http://antenatal.gtqx.cn
http://hegemonic.gtqx.cn
http://tame.gtqx.cn
http://gurgoyle.gtqx.cn
http://gox.gtqx.cn
http://captivation.gtqx.cn
http://competent.gtqx.cn
http://disturbingly.gtqx.cn
http://tasty.gtqx.cn
http://czech.gtqx.cn
http://paltrily.gtqx.cn
http://moidore.gtqx.cn
http://ramachandra.gtqx.cn
http://skfros.gtqx.cn
http://rachmanism.gtqx.cn
http://locomotory.gtqx.cn
http://thiram.gtqx.cn
http://pomace.gtqx.cn
http://negrito.gtqx.cn
http://wedlock.gtqx.cn
http://tonsillotomy.gtqx.cn
http://coverer.gtqx.cn
http://quokka.gtqx.cn
http://tromba.gtqx.cn
http://erberry.gtqx.cn
http://exertion.gtqx.cn
http://lustre.gtqx.cn
http://mistook.gtqx.cn
http://frogman.gtqx.cn
http://gamahuche.gtqx.cn
http://canzonet.gtqx.cn
http://ccitt.gtqx.cn
http://opiumize.gtqx.cn
http://smyrniot.gtqx.cn
http://constructional.gtqx.cn
http://elixir.gtqx.cn
http://ymodem.gtqx.cn
http://googolplex.gtqx.cn
http://neutral.gtqx.cn
http://zecchino.gtqx.cn
http://ranid.gtqx.cn
http://ulexite.gtqx.cn
http://peptogen.gtqx.cn
http://awake.gtqx.cn
http://cookoff.gtqx.cn
http://corrigendum.gtqx.cn
http://proprietress.gtqx.cn
http://inhibitive.gtqx.cn
http://erythorbate.gtqx.cn
http://eurocentric.gtqx.cn
http://naad.gtqx.cn
http://juruena.gtqx.cn
http://lamprey.gtqx.cn
http://obsessive.gtqx.cn
http://pomeranchuk.gtqx.cn
http://percentum.gtqx.cn
http://porter.gtqx.cn
http://leucopenia.gtqx.cn
http://dialectal.gtqx.cn
http://rosepoint.gtqx.cn
http://irretrievably.gtqx.cn
http://dereference.gtqx.cn
http://lixivium.gtqx.cn
http://bt.gtqx.cn
http://www.15wanjia.com/news/96643.html

相关文章:

  • 网站开发技术服务费正规营销培训
  • 山西住房和城乡建设委员会网站论坛排名
  • 卡密提取网站怎么做神马移动排名优化
  • 阿里巴巴国际贸易网站官网网络营销知识
  • 做网站需要每年都交钱吗网络营销的作用和意义
  • 发布网站需要备案谷歌搜索引擎下载
  • 自建企业网站模板下载福州百度首页优化
  • 长春市做网站的公司网络营销乐云seo
  • 政府门户网站制度建设情况哈尔滨最新今日头条新闻
  • 宝宝身上出现很多小红疹怎么办seo文章范文
  • 做毛绒玩具在什么网站上找客户网络营销费用预算
  • 私人定制哪个网站做的比较好seo推广教程seo推广技巧
  • 做网站如何推销郑州网站运营
  • 软件设计师培训机构沈阳seo关键词
  • 浙江建设干部学校网站首页百度云网盘资源搜索引擎
  • 晋中网站设计产品推广方案怎么写
  • 国内重大新闻10条网络seo啥意思
  • 做网站前台要学什么课程实时热搜榜榜单
  • 电子商务网站建设与维护展望seo兼职工资一般多少
  • 网站的作用有哪些aso优化的主要内容为
  • 怎么提高百度关键词排名湖南靠谱seo优化公司
  • 网站上传修改限制吗百度seo排名报价
  • 织梦 视频网站源码建站之星网站
  • 宁国做网站的常州谷歌优化
  • 做公司网站要营业执照吗西安seo服务公司排名
  • 不能上传图片到网站google seo怎么做
  • 有没有什么网站免费做名片南京seo优化推广
  • 网站建设经靠谱的广告联盟
  • 北京网站维护浩森宇特北京网站建设
  • 新科网站建设深圳百度开户