Dynamic programming question

前端 未结 5 751
北海茫月
北海茫月 2021-02-02 02:55

A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and light

相关标签:
5条回答
  • 2021-02-02 03:02

    Result of 1 and 2 has to be same. It's not possible that one of them is shorter, because in a solution elements are descending both in height and weight so if it satisfies 1 or 2 it will satisfy the other as well, If it would be shorter it wouldn't be the longest.

    0 讨论(0)
  • 2021-02-02 03:02

    As far as I can see, this is the same question as Box stacking problem:

    Also: http://people.csail.mit.edu/bdean/6.046/dp/

    0 讨论(0)
  • 2021-02-02 03:05

    It doesn't make any difference. And it is unnecessary to pre-sort as you end up with the same graph to search.

    0 讨论(0)
  • 2021-02-02 03:06

    You might need to say something about the weights & heights all being unique. Otherwise, if

    A is (10, 10) // (w, h)
    B is ( 9, 10)
    C is ( 9,  8)
    

    Then neither method gets the correct answer! C obviously can stand on A's shoulders.


    Edit:

    Neither method is good enough!

    Example with all weights & heights unique:

    A : (12, 12)
    B : (11,  8)
    C : (10,  9)
    D : ( 9, 10)
    E : ( 8, 11)
    F : ( 7,  7)
    

    Both methods give an answer of 2, however the tower can be at least of height 3 with several combinations:

    • A on the bottom,
    • then any of B, C, D, or E,
    • then F on top.

    I think stricter rules on the input data are needed to make this problem solvable by the given methods.

    0 讨论(0)
  • 2021-02-02 03:25

    You're absolutely correct. Doing just one direction is enough.

    A proof is easy by using the maximum property of the subsequence. We assume one side (say the left) of values is ordered, and take the longest descending subsequence of the right. We now perform the other operation, order the right and take the subsequence from the left.

    If we arrive at a list that is either shorter or longer than the first one we found we have reached a contradiction, since that subsequence was ordered in the very same relative order in the first operation, and thus we could have found a longer descending subsequence, in contradiction to the assumption that the one we took was maximal. Similarly if it's shorter then the argument is symmetrical.

    We conclude that finding the maximum on just one side will be the same as the maximum of the reverse ordered operation.

    Worth noting that I haven't proven that this is a solution to the problem, just that the one-sided algorithm is equivalent to the two-sided version. Although the proof that this is correct is almost identical, assume that there exists a longer solution and it contradicts the maximalness of the subsequence. That proves that there is nothing longer, and it's trivial to see that every solution the algorithm produces is a valid solution. Which means the algorithm's result is both >= the solution and <= the solution, therefore it is the solution.

    0 讨论(0)
提交回复
热议问题