Are these two problems or just one?
[QUOTE]任意给定5个数字,其中必定存在3个数字已经有序(或者升序,或者降序),找出这5个数字中最长的升序或降序序列。
例如:1,7,5,3,9。则{1,7,9},{1,5,9},{1,3,9}都是最长的升序序列;
而{7,5,3}是最长的降序序列。
再如:1,3,2,5,7。最长的升序序列为{1,3,5,7}和{1,2,5,7}。[/QUOTE]
This can be done by first copy your sequence a to another sequence b,
sort b, and then find the larget common subsequence of a and b.
You should be able to write your own algorithm for LCS.
[QUOTE]
自动生成各种可能的序列,对于5个数字所有可能的序列为:
{0,1,2,3}、{0,1,2,4}、{0,1,3,4}、{0,2,3,4}、{1,2,3,4}
{0,1,2}、{0,1,3}、{0,2,3}、{1,2,3}
{0,1,4}、{0,2,4}、{1,2,4}
{1,3,4}
{2,3,4}、{0,3,4}
考察各种可能的序列是否升序或是降序,若是则打印;[/QUOTE]
This can be done by using some recursive algorithm to permute the numbers. You may first want to try to generate all the n! permutations for 1..n.