hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
2014-11-27 19:00
417 查看
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[550],b[550],dp[550][550]; int main() { int n,m,i,j,temp; int cas; scanf("%d",&cas); while(cas--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&m); for(i=1;i<=m;i++) scanf("%d",&b[i]); for(i=0;i<=m;i++) dp[0][i]=0; for(i=1;i<=n;i++) { temp=0; for(j=1;j<=m;j++) { dp[i][j]=dp[i-1][j]; if(a[i]>b[j]&&dp[i-1][j]>temp) temp=dp[i-1][j]; if(a[i]==b[j]) dp[i][j]=temp+1; } } int ans=0; for(i=1;i<=m;i++) ans=max(ans,dp [i]); printf("%d\n",ans); if(cas!=0) printf("\n"); } return 0; }
相关文章推荐
- hdu 1423 Greatest Common Increasing Subsequence(DP 最长公共上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence(DP 最长公共上升子序列)
- HDU 1423 Greatest Common Increasing Subsequence (最长公共上升子序列)【模板】
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列dp)
- 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(最长上升公共子序列)
- Greatest Common Increasing Subsequence hdu1423 最长公共递增子序列
- 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_LICS(最长公共递增子序列)
- HDU1423&ZOJ2432 - Greatest Common Increasing Subsequence(LCIS最长公共上升子序列模板)
- zoj 2432 Greatest Common Increasing Subsequence(最长公共上升子序列)
- POJ 2127 Greatest Common Increasing Subsequence (最长公共上升子序列+记录路径)
- HDU 1423(Greatest Common Increasing Subsequence)公共最长不降子序列
- 最长公共上升子序列——hdu1423 Greatest Common Increasing Subsequence