• HDU 1423 Greatest Common Increasing Subsequence


    Greatest Common Increasing Subsequence

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 8060    Accepted Submission(s): 2600


    Problem Description
    This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.
     
    Input
    Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.
     
    Output
    output print L - the length of the greatest common increasing subsequence of both sequences.
     
    Sample Input
    1
    5
    1 4 2 5 -12
    4
    -12 1 2 4
     
    Sample Output
    2
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <iomanip>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define INF 0x3f3f3f3f3f
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int dp[1006];
    int a[1006];
    int b[1006];
    int n,m,t;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            int maxn;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
            }
            scanf("%d",&m);
            for(int i=1;i<=m;i++)
            {
                scanf("%d",&b[i]);
            }
            memset(dp,0,sizeof(dp));
            for(int i=1;i<=n;i++)
            {
                maxn=0;
                for(int j=1;j<=m;j++)
                {
                    if(a[i]>b[j]) maxn=max(dp[j],maxn);
                    if(a[i]==b[j]) dp[j]=maxn+1;
                }
            }
            maxn=0;
            for(int i=1;i<=m;i++)
                maxn=max(dp[i],maxn);
            printf("%d
    ",maxn);
            if(t) printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    sina sae搭建wordpress数据库配置
    Daper返回DataTable
    第4章 jQuery中的事件和动画
    第3章 ,jQuery中的DOM操作
    第2章 jQuery选择器
    第1章 认识jQuery
    MyBatis基本查询、条件查询、查询排序
    《Head First Servlets & JSP》-13-过滤器和包装器
    《Head First Servlets & JSP》-12-Web应用安全
    《Head First Servlets & JSP》-11-Web应用部署
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7230879.html
Copyright © 2020-2023  润新知