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 6935373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:05:39+00:00 2026-05-27T12:05:39+00:00

I have this question on a practise exam, and have no idea how to

  • 0

I have this question on a practise exam, and have no idea how to solve it, so I’m very scared for the final. Anyways, finding that this problem has an answer would be relieving and would help me understand dynamic programming, so thanks for reading 🙂

Problem:

Given a sequence of n numbers a1, …, an (positive or negative), we
want to divide the sequence into blocks so as to minimize the sum of
the squares of the block sums, subject to the constraint that each
block contains at least 2 and at most 4 elements. In other words, we
want to find 1 = i[0] < i[1] < i[2] < … < i[k-1] < i[k] = n + 1 to
minimize (ai[0] + … + ai[1]-1)^2 + (ai[1] + … + ai[2]-1)^2 + … +
(ai[k-1] + … + ai[k]-1)^2, such that 2 <= i[1] – i[0] <= 4, 2 <=
i[2] – i[1] <= 4, …, 2 <= i[k] – i[k-1] <= 4. (Note that the number
of blocks k is not given.) Present an O(n)-time dynamic programming
algorithm to solve the problem.

My problem: defining the subproblems. My only clue is to continuously find the minimum sums of length 4 down to 2, but what if there is 1 leftover? Does it join with an existing group of length 2 or 3, or does a 4-group split? Let alone getting it done in O(n)…

  • 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-27T12:05:39+00:00Added an answer on May 27, 2026 at 12:05 pm

    The subproblem is: Find the miminum across the first k numbers.
    Here is how you reduce the problem to already solved subproblems:

    Let F(k) be the minimum sum of squares when solved for a1, a2, ... ak.

    Now

    F(2) = (a1+a2)^2
    F(3) = (a1+a2+a3)^2
    F(4) = min { (a1+a2+a3+a4)^2, (a1+a2)^2 + (a3+a4)^2 }
    F(5) = min { (a1+a2+a3)^2 + (a4+a5)^2, (a1+a2)^2 + (a3+a4+a5)^2 }
    
    F(n) = min {
                  F(n-2) + (a[n-1]+a[n])^2,
                  F(n-3) + (a[n-2]+a[n-1]+a[n])^2,
                  F(n-4) + (a[n-3]+a[n-2]+a[n-1]+a[n])^2
           }
    

    You can write a simple function that computes F(k) for increasing values of k and stores them in an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little question that's been on my mind for a while now.
Well, this is another question taken from this practice exam that was given to
I have read this question and I want to add to it that what
I have this question in which I have a SQL Server Compact Edition database
I have this question because I am not familiar latest generation of MS VS
I have this question: How could I call a codebehind method from jquery? I
I have this question relating to Lucene. I have a form and I get
I have this question, i am just throwing it out there. I am implementing
Dear all,Now i have this question in my java program,I think it should be
ASP.Net MVC3 is cool and all but I have this question more out of

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.