http://acm.hdu.edu.cn/showproblem.php?pid=1423 题目大意:就是叫你求最长公共递增子序列的长度。So就用LCIS算法做了。 #include <stdio.h> #include <string.h> const int size = 505; int a[size],b[size]; int len[size];/*b字符串到第j个字符时,该字符位置处的公共递增因子数*/ int LCIS(int M,int N) { int locate,i,j,Max = -1; memset(len,0,sizeof(len)); len[0] = -1; for (i=1;i<=M;i++) { locate=0; for (j=1;j<=N;j++) { /*当前要比较的数值为a[i],所以我们寻找b[j]中比a[i]小,但len[j]最大的值,找到了就用locate记录位置*/ if(b[j]<a[i]&&len[j]>len[locate]) locate = j; if(b[j] == a[i]) len[j] = (len[locate]>=0?len[locate]:0)+1;/*len[locate]值+1就为当前字符的公共递增因子数*/ } } for(i=1;i<=N;i++) if(len[i]>Max) Max = len[i]; return Max; } int main() { int M,N,NumOfTest,i; scanf("%d",&NumOfTest); while (NumOfTest--) { scanf("%d",&M); for(i=1;i<=M;i++) scanf("%d",&a[i]); scanf("%d",&N); for(i=1;i<=N;i++) scanf("%d",&b[i]); printf("%d/n",LCIS(M,N)); if(NumOfTest) printf("/n"); } return 0; }