Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:01:04+00:00 2026-05-23T10:01:04+00:00

I found the following problem on the internet, and would like to know how

  • 0

I found the following problem on the internet, and would like to know how I would go about solving it:

Problem: Integer Partition without Rearrangement

Input: An arrangement S of non negative numbers {s1, . . .
, sn} and an integer k.

Output: Partition S into k or fewer ranges, to minimize the maximum
of the sums of all k or fewer ranges,
without reordering any of the
numbers.*

Please help, seems like interesting question… I actually spend quite a lot time in it, but failed to see any solution..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:01:04+00:00Added an answer on May 23, 2026 at 10:01 am

    Let’s try to solve the problem using dynamic programming.

    Note: If k > n we can use only n intervals.

    Let consider d[ i ][ j ] is solution of the problem when S = {s1, …, si } and k = j. So it is easy to see that:

    1. d[ 0 ][ j ] = 0 for each j from 1 to k
    2. d[ i ][ 1 ] = sum(s1…si) for each i from 1 to n
    3. d[ i ][ j ] = minfor t = 1 to i (max ( d[i – t][j – 1], sum(si – t + 1…si)) for i = 1 to n and j = 2 to k

    Now let’s see why this works:

    1. When there is no elements in the sequence it is clear that only one interval there can be (an empty one) and sum of its elements is 0. That’s why d[ 0 ][ j ] = 0 for all j from 1 to k.
    2. When only one interval there can be, it is clear that solution is sum of all elements of the sequence. So d[ i ][ 1 ] = sum(s1…si).
    3. Now let’s consider there are i elements in the sequence and number of intervals is j, we can assume that last interval is (si – t + 1…si) where t is positive integer not greater than i, so in that case solution is max ( d[i – t][j – 1], sum(si – t + 1…si), but as we want the solution be minimal we should chose t such to minimize it, so we will get minfor t = 1 to i (max ( d[i – t][j – 1], sum(si – t + 1…si)).

    Example:

    S = (5,4,1,12), k = 2

    d[0][1] = 0, d[0][2] = 0

    d[1][1] = 5, d[1][2] = 5

    d[2][1] = 9, d[2][2] = 5

    d[3][1] = 10, d[3][2] = 5

    d[4][1] = 22, d[4][2] = 12

    Code:

    #include <algorithm>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    int main ()
    {
        int n;
        const int INF = 2 * 1000 * 1000 * 1000;
        cin >> n;
        vector<int> s(n + 1);
        for(int i = 1; i <= n; ++i)
            cin >> s[i];
        vector<int> first_sum(n + 1, 0);
        for(int i = 1; i <= n; ++i)
            first_sum[i] = first_sum[i - 1] + s[i];
        int k;
        cin >> k;
        vector<vector<int> > d(n + 1);
        for(int i = 0; i <= n; ++i)
            d[i].resize(k + 1);
        //point 1
        for(int j = 0; j <= k; ++j)
            d[0][j] = 0;
        //point 2
        for(int i = 1; i <= n; ++i)
            d[i][1] = d[i - 1][1] + s[i]; //sum of integers from s[1] to s[i]
        //point 3
        for(int i = 1; i <= n; ++i)
            for(int j = 2; j <= k; ++j)
            {
                d[i][j] = INF;
                for(int t = 1; t <= i; ++t)
                    d[i][j] = min(d[i][j], max(d[i - t][j - 1], first_sum[i] - first_sum[i - t]));
            }
    
    
        cout << d[n][k] << endl;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is a lot of information in the Internet about solving this
I did my research but haven't found an answer to the following problem: I
I found the following article : here about installing fonts on a Windows computer
I am merging two examples found on the internet. One about stretched selection styles
I searched from internet, but I only found php solutions to this problem. Please
Reading through documentation, I found following: 1.9.1 1.8.4 1.8.2 A version of 1.8.2 select
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I found the following table structures while I was watching ruby on rails tutorial.
I found the following code somewhere, but I am not understanding the code properly.
I found the following syntax as a VB.NET property and I'm trying to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.