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

  • Home
  • SEARCH
  • 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 8215507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:48:38+00:00 2026-06-07T11:48:38+00:00

I am trying to go over some notes and examples of dynamic programming, and

  • 0

I am trying to go over some notes and examples of dynamic programming, and I have having some difficulty figuring out how it all works. I will post the question, and then what I am having difficulty with:

Given a sequence of points p1= (x1,y1),…,pn=(xn,yn) sorted from left to right (ie, x1 < x2 < … < xn) and a number k between 1 and n, find a polygonal chain from p1 to pn with k edges that goes from left to right, minimizing the sum of the vertical distances of the points to the chain. Design dynamic programming algorithm that solves the problem in O(n^3) time. Set the subproblems, give all base cases necessary, calculate recursive formula, and write pseudocode for the algorithm. Also a function f(a,b) is defined for us to use in calculating the vertical difference, so I dont have to worry about implementing that. I can just use it as f(a,b)

I believe that the subproblems should be divided as such:

C[i,j] = polygonal chain from p1 to pi with j edges, minimizing the sum of vertical distances.

And then the answer would be: C[n,k]

Base case: C[i,0] = 0

And now I am having some difficulty coming up with the recursive formula. My first question, have I broken the subproblems up correctly? The question gives a hint that makes it seem like I did, but I am not 100% sure. If I am, any hints on how to proceed with deriving the recursive formula?

Thanks for any help guys.

  • 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-06-07T11:48:40+00:00Added an answer on June 7, 2026 at 11:48 am

    Your subproblems are correct, but I think a little change to the formulation can help you come up with the formula:

    Instead of having C(i, j) mean any chain from 1 to i with j edges, make it mean specifically “A chain that ends in i”. Then, to determine the answer for C(i, j) you just have to try all the possibilities for where the last edge started.

    Then the answer can be the optimal of all C(i, k).

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

Sidebar

Related Questions

I having some trouble trying to figure out how to implement a Rails 3
I have looked over the web and found some cool examples of MVC implementation
I'm trying to run some statistics over the Stack Overflow data dump, and for
I'm trying to make a picture over picture fading with some text appearing on
I am trying to benchmark some code. I am sending a String msg over
We just moved over to Git from SVN. In trying to clean up some
As a project over summer while I have some downtime from Uni I am
http://jsfiddle.net/jasondavis/Mt87G/1/ I am trying to do an un-ordered list, each list item will have
I keep having issues iterating over some JSON to put in select options (btw,
I'm trying to iterate over checkboxes in an ASP.Net web page, and if any

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.