这一题题意理解起来有点困难,汗,这个对题目意思解释比较详细,我是看了这个题目解释才做出来的http://www.byywee.com/page/M0/S259/259491.html
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio>
2 #include <cstring>
3
4 int in[30];
5 int right[30];
6 int dp[30];
7 int b[30];
8
9 int main()
10 {
11 int n;
12 int a;
13 scanf("%d",&n);
14 for(int i = 1;i <= n;i ++)
15 {
16 scanf("%d",&b[i]);
17 }
18
19 while(scanf("%d",&a) == 1)
20 {
21 int k = 1;
22 in[a] = k;
23 for(k = 2;k <= n;k ++)
24 {
25 scanf("%d",&a);
26 in[a] = k;
27 }
28
29 for(int i = 1;i <= n;i ++)
30 {
31 right[i] = b[in[i]];
32 }
33
34 int maxn = 0;
35 memset(dp,0,sizeof(dp));
36 dp[1] = 1;
37 for(int i = 2;i <= n;i ++)
38 {
39 dp[i] = 1;
40 for(int j = 1;j < i;j ++)
41 {
42 if(right[i] > right[j]&&dp[i] < dp[j] + 1)
43 dp[i] = dp[j] + 1;
44 }
45 if(dp[i] > maxn)
46 maxn = dp[i];
47 }
48
49 printf("%d\n",maxn);
50 }
51
52 return 0;
53 }