Given a sequence S of N digits, find a subsequence of K digits such that the number formed by these K digits, in order, is the largest.
这道题要求从一个由 N 个数字组成的序列中,按原顺序选出 K 个数字,使拼成的数尽可能大。核心思路通常是贪心:从左到右维护一个单调递减结构,遇到更大的数字时,尽量删除前面较小的数字,但总删除次数不能超过 N-K。这样可以保证在保留相对顺序的前提下,让高位尽可能大。这个问题本质上考察的是贪心、单调栈以及对子序列最大化的理解。
正文完