题目链接:http://codeforces.com/contest/10/problem/D
题意:给你两个串,求公共最长上升子序列
解法:ORZZZZ

//CF 10D

#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn], b[maxn];
int dp[maxn]; //dp[i]表示第二个串位置为i的时候与第一个串的的最长公共上升子序列是多少
int n, m;
int step[maxn];
void print(int x){
    if(x == 0) return;
    print(step[x]);
    printf("%d ", b[x]);
}

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for(int i = 1; i <= m; i++) scanf("%d", &b[i]);

    for(int i = 1; i <= n; i++){
        int pos = 0;
        for(int j = 1; j <= m; j++){
            if(a[i] == b[j]){
                dp[j] = dp[pos] + 1;
                step[j] = pos;
            }
            if(a[i] > b[j] && dp[pos] < dp[j]){
                pos = j;
            }
        }
    }

    int ans = 0, ans2 = 0;
    for(int i = 1; i <= m; i++){
        if(dp[i] > ans2){
            ans2 = dp[i], ans = i;
        }
    }
    printf("%d\n", ans2);
    print(ans);
    return 0;
}