Greatest Common Increasing Subsequence
time limit per test 1 second memory limit per test 256 megabytes
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.

传送门:HDU1423

Input

Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.

Output

output print L - the length of the greatest common increasing subsequence of both sequences.

Sample Input

1
2
3
4
5
1
5
1 4 2 5 -12
4
-12 1 2 4

Sample Output

1
2

题解

LCIS模板
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.*;  
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
int t=sc.nextInt();
while(sc.hasNext()){
t--;
int n=sc.nextInt();
int[]a=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=sc.nextInt();
}
int m=sc.nextInt();
int[]b=new int[m+1];
for(int i=1;i<=m;i++){
b[i]=sc.nextInt();
}
int[][]dp=new int[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i]!=b[j]){
dp[i][j]=dp[i-1][j];
}else{
int maxl=0;
for(int k=1;k<j;k++){
if(b[k]<b[j])
maxl=Math.max(maxl, dp[i-1][k]);
}
dp[i][j]=maxl+1;
}
}
}
int res=-1;
for(int i=1;i<=m;i++){
res=Math.max(res, dp[n][i]);
}
pw.println(res);
if(t!=0)
pw.println();
pw.flush();
}

}
int LCIS(int n,int m)
{
int k;
int sum=0;
for(int i=1;i<=n;i++)
{
k=0;
for(int j=1;j<=m;j++)
{
dp[i][j]=dp[i-1][j];
if(a[i]==b[j])
//ss[j]=k+1;
dp[i][j]=k+1;
else if(a[i]>b[j])
{
//if(k<ss[j])
// k=ss[j];
if(k<dp[i-1][j])
k=dp[i-1][j];
}
}
}
for(int i=1;i<=m;i++)
//sum=max(sum,ss[i]);
if(sum<dp[n][i])
sum=dp[n][i];
return sum;
}
}