Advertisement

出栈序列是否合法(C语言实现)

阅读量:

题目

Consider a stack with a maximum capacity of M numbers. Pushing N sequential integers from 1 to N followed by random pops. The task is to determine whether a given sequence qualifies as a potential pop sequence from the stack. For instance, when M equals five and N equals seven it's possible to achieve the sequence [1-7] but not [3-2-1-7-5-6-4].

Input Specification:

Each input file includes one test case. For each test case, the first line of the input contains three numbers: M (representing the maximum capacity of the stack), N (representing the length of the push sequence), a

全部评论 (0)

还没有任何评论哟~