HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
2014-03-29 20:50
381 查看
Greatest Common Increasing Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3460 Accepted Submission(s): 1092
[align=left]Problem Description[/align]
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.
[align=left]Input[/align]
Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.
[align=left]Output[/align]
output print L - the length of the greatest common increasing subsequence of both sequences.
[align=left]Sample Input[/align]
1 5 1 4 2 5 -12 4 -12 1 2 4
[align=left]Sample Output[/align]
2
[align=left]Source[/align]
ACM暑期集训队练习赛(二)
代码:动态规划求最长增长公共序列 下面展示的是压缩空间的lcs,由于不需要记录顺序,所以这样写,较为简便,如果要记录路径只需要将lcs[]--->换成lcs[][],
然后maxc,变为lcs[][]的上一行即可!
//增长lcs algorithm #include<stdio.h> #include<string.h> #define maxn 505 int aa[maxn],bb[maxn]; int lcs[maxn]; int main() { int test,na,nb,i,j,maxc,res; scanf("%d",&test); while(test--) { scanf("%d",&na); for(i=1;i<=na;i++) scanf("%d",aa+i); scanf("%d",&nb); for(j=1;j<=nb;j++) scanf("%d",bb+j); memset(lcs,0,sizeof(lcs)); for(i=1;i<=na;i++) { maxc=0; for(j=1;j<=nb;j++) { if(aa[i]==bb[j]&&lcs[j]<maxc+1) lcs[j]=maxc+1; if(aa[i]>bb[j]&&maxc<lcs[j]) maxc=lcs[j]; } } res=0; for(i=1;i<=nb;i++) if(res<lcs[i])res=lcs[i]; printf("%d\n",res); if(test) putchar(10); } return 0; }
相关文章推荐
- zoj 2432 && hdoj 1423 Greatest Common Increasing Subsequence 【打印LCIS】
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列dp)
- Greatest Common Increasing Subsequence poj-1423
- hdu 1423 Greatest Common Increasing Subsequence_LICS(最长公共递增子序列)
- HDU 1423 Greatest Common Increasing Subsequence (LCIS)
- hdu 1423 greatest common increasing subsequence
- HDU 1423 Greatest Common Increasing Subsequence
- Greatest Common Increasing Subsequence hdu1423 最长公共递增子序列
- HDU 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence_LCIS
- hdoj 1423 Greatest Common Increasing Subsequence(最长上升公共子序列)
- HDU 1423 Greatest Common Increasing Subsequence
- 8月3号的LCS,LIS,LICS:Longest Ordered Subsequence&&Common Subsequence&&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
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
- HDU 1423 Greatest Common Increasing Subsequence LCIS