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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:21:14+00:00 2026-05-13T19:21:14+00:00

I found this famous dp problem in many places, but I can not figure

  • 0

I found this famous dp problem in many places, but I can not figure out how to solve.

You are given a set of n types of
rectangular 3-D boxes, where the i^th
box has height h(i), width w(i) and
depth d(i) (all real numbers). You
want to create a stack of boxes which
is as tall as possible, but you can
only stack a box on top of another box
if the dimensions of the 2-D base of
the lower box are each strictly larger
than those of the 2-D base of the
higher box. Of course, you can rotate
a box so that any side functions as
its base. It is also allowable to use
multiple instances of the same type of
box.

This problem seems too complicated for me to figure out the steps. As it is 3D, I get three sequence of height, width and depth. But as it is possible to exchange 3 dimension the problem becomes more complicated for me. So please someone explain the steps to solve the problem when there is no swapping and then how to do it when swapping. I became tired about the problem. So please, please someone explain the solution easy way.

  • 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-13T19:21:14+00:00Added an answer on May 13, 2026 at 7:21 pm

    I think you can solve this using the dynamic programming longest increasing subsequence algorithm: http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence

    Accounting for the rotations is easy enough: for every tower all you have to check is what happens if you use its height as the length of the base and its width as the height and what happens if you use it in the natural way. For example:

    =============
    =           =
    =           =
    =           = L
    =     H     =
    =           =
    =           =
    =============   
          W
    

    Becomes something like (yeah, I know it looks nothing like it should, just follow the notations):

    ==================
    =                =
    =                =  
    =       W        = L
    =                =
    =                =
    ==================
            H
    

    So for each block you actually have 3 blocks representing its possible rotations. Adjust your blocks array according to this, then sort by decreasing base area and just apply the DP LIS algorithm to the get the maximum height.

    The adapted recurrence is: D[i] = maximum height we can obtain if the last tower must be i.

    D[1] = h(1);
    D[i] = h(i) + max(D[j] | j < i, we can put block i on top of block j)
    
    Answer is the max element of D.
    

    See a video explaning this here: http://people.csail.mit.edu/bdean/6.046/dp/

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

Sidebar

Related Questions

Found this recently, but can't for the life of me figure out how the
found this function online, which works great... except I can't figure out how to
Found this Multimap containing pairs? , but it is not much help How would
i found this code but do not quite understand what the command is doing.
Found this code that breaks out CSV fields if contains double-quotes But I don't
This is a very famous questions in Google. I found several suggestion to achieve
Found This: tyty stack, Social Icons not working with Infinite Scrolling on Wordpress I'm
found this little code snippet that seems to do what i want, but im
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can

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.