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;
    }
  • 相关阅读:
    Excel求值表达式——太好用了
    CPU保护模式深入探秘
    用QT创建WINDOWS服务程序
    windows服务怎么向应用程序发消息(部署在同一台机,非SCOKET)
    TCP的流量控制和拥塞控制
    PHP:执行模型和内存模型
    Web API CSRF保护实现
    C#中易混淆的知识点
    字符串合并与拆分写法小结
    zabbix实现对磁盘动态监控
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7230879.html
Copyright © 2011-2022 走看看