Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0147 - GREATEST COMMON INCREASING SUBSEQUENCE |
You are given two sequences of integer numbers. Write a program to determine their common increasing subsequence of maximal possible length.
Sequence S1, S2, . . . , SN of length N is called an increasing subsequence of a sequence A1, A2, . . . , AM of length M if there exist 1 ≤ i1 < i2 < . . . < iN ≤ M such that Sj = Aij for all 1 ≤ j ≤ N , and Sj < Sj+1 for all 1 ≤ j < N .
Input
Each sequence is described with M — its length (1 ≤ M ≤ 500) and M integer numbers Ai (−231 ≤ Ai < 231) — the sequence itself.
Output
On the first line of the output file print L — the length of the greatest common increasing subsequence of both sequences. On the second line print the subsequence itself. If there are several possible answers, output any of them.
Examples
№ |
stdin |
stdout |
1 |
5 |
2 1 4 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-04-09 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | Northern QF 2003.G |