zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    iPhone X 的“刘海”正是苹果的品牌象征
    中国首届原型设计大赛在成都举办
    hdu1114Piggy-Bank(完全背包)
    hdu2602Bone Collector(01背包)
    漏洞百出的线段树!!
    hdu1078FatMouse and Cheese
    hdu2859Phalanx
    poj3186Treats for the Cows(区间dp)
    uva10088格点多边形
    快速幂快速乘
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7230879.html
Copyright © 2011-2022 走看看