Re: [問題]n位整數拿掉m數字得到最大數值

作者: Leon (Achilles)   2013-11-15 11:10:06
※ 引述《PATRICKSTARS (PatrickStar)》之銘言:
: Given an integer (not necessary a decimal number) with n digits, we want to
: remove m (<=n) digits from this number such that the resulting number is as
: large as possible. Design an O(n) time algorithm to solve it.
: 可以提示如何下手嗎?
嗯, 我看了一下.
Range Minimum Query (RMQ) 似乎不太對啊.
舉個簡單的例子好了(有人已經點出來了)
2-3-4-5-1-1, remove 2 digits
RMQ 應該會得到 2-3-4-5,
但這題的最佳解應該是 4-5-1-1.
(希望我沒有誤解你的意思)
我認為這題呢, 要用 increasing sequence 的觀念去看.
從簡單的 case 出發:
1-2-3-4, increasing sequence, so everytime we remove,
we start from begining.
4-3-2-1, decreasing sequence, then we remove from back.
Thus, when we work on it,
we start from making the leading sequence as a decreasing sequence,
then remove the inflection point.

Links booklink

Contact Us: admin [ a t ] ucptt.com