Try Again

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\n",maxn);
        if(t) printf("\n");
    }
    return 0;
}

 

posted @ 2017-07-24 20:21  十年换你一句好久不见  阅读(171)  评论(0编辑  收藏  举报