HDU 1423 Greatest Common Increasing Subsequence
2010-03-20 11:30
288 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1423
题目大意:就是叫你求最长公共递增子序列的长度。So就用LCIS算法做了。
题目大意:就是叫你求最长公共递增子序列的长度。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; }
相关文章推荐
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列LICS)
- HDU 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
- HDU 1423 Greatest Common Increasing Subsequence 最长公共递增序列
- HDU 1423 - Greatest Common Increasing Subsequence
- HDU 1423 Greatest Common Increasing Subsequence
- HDU 1423 Greatest Common Increasing Subsequence(LCIS)
- HDU 1423 Greatest Common Increasing Subsequence (最长公共上升子序列)【模板】
- hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
- HDU 1423 Greatest Common Increasing Subsequence(最长公共子序列+最长不下降子序列)
- hdu 1423 Greatest Common Increasing Subsequence(不连续子序列)
- HDU 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence (最长上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence (最长上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列、LCIS)
- 【HDU 1423】Greatest Common Increasing Subsequence【LCIS 裸题】
- hdu 1423 Greatest Common Increasing Subsequence(最长上升公共子序列)
- hdu 1423 greatest common increasing subsequence
- hdu 1423 Greatest Common Increasing Subsequence