410. Split array largest Sum divides the array into M-groups, how to make the maximum and minimum

Source: Internet
Author: User

[Copy question]:

Given an array which consists of non-negative integers and a integer m, you can split the array into m Non-empty continuous subarrays. Write a algorithm to minimize the largest sum among these m subarrays.

Note:
If N is the length of an array, assume the following constraints is satisfied:

    • 1 ≤ n ≤1000
    • 1 ≤ m ≤min ( n)

Examples:

Input:nums = [7,2,5,10,8]m = 2output:18explanation:there is four ways to split nums into and Subarrays. The best-of-the-is-to-split it into [7,2,5] and [10,8],where the largest sum among the "the" and "is" only 18.

[Brute force solution]:

Time Analysis:

Spatial Analysis:

[After optimization]:

Time Analysis:

Spatial Analysis:

[Wonderful output CONDITIONS]:

[Wonderful corner case]:

[Thinking questions]:

I don't know why. Using dichotomy: dichotomy can find a position by moving mid

[English data structure or algorithm, why not other data structures or algorithms]:

[a sentence of thought]:

Unexpectedly: The largest number must be separated, see can be left to draw several numbers and it a group

[7,2,5,10,8,105550]3 return 105550 

Group no more than M, extend left or right

[input]: null: Normal: Large: Extra Small: Special cases handled in the program: abnormal conditions (unreasonable input):

[Drawing]:

[One brush]:

[Two brushes]:

[Three brushes]:

[Four brushes]:

[Five brushes]:

[Results of five-minute visual debug]:

[Summary]:

Try a few more , and you'll see.

[Complexity]:time Complexity:o () Space complexity:o ()

[Algorithmic thinking: Recursion/division/greed]:

[Key templating code]:

[Other solutions]:

[Follow up]:

[The problem given by the LC becomes variable]:

[Code Style]:

[Whether to write this type of driver Funcion code for the first time]:

410. Split array largest Sum divides the array into M-groups, how to make the maximum and minimum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.