zoukankan      html  css  js  c++  java
  • Greatest Common Increasing Subsequence hdu1423

    Greatest Common Increasing Subsequence

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


    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
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #define clr(x,y) memset(x,y,sizeof(x))
     5 using namespace std;
     6 int a[600],b[600],ans[600],an,bn;
     7 int work()
     8 {
     9     memset(ans,0,sizeof(ans));
    10     int i,j,t,maxa,maxan=0;
    11     for(i=1; i<=an; i++)
    12     {
    13         maxa=0;
    14         for(j=1; j<=bn; j++)
    15         {
    16             if(a[i]>b[j]&&ans[j]>maxa)maxa=ans[j];
    17             if(a[i]==b[j]&&ans[j]<maxa+1)
    18                 ans[j]=maxa+1;
    19         }
    20     }
    21     for(i=1;i<=bn;i++)
    22         if(ans[i]>maxan)maxan=ans[i];
    23     return maxan;
    24 }
    25 int main()
    26 {
    27     int t,i;
    28     scanf("%d",&t);
    29     while(t--)
    30     {
    31         scanf("%d",&an);
    32         for(i=1; i<=an; i++)scanf("%d",&a[i]);
    33         scanf("%d",&bn);
    34         for(i=1; i<=bn; i++)scanf("%d",&b[i]);
    35         printf("%d
    ",work());
    36         if(t)printf("
    ");
    37     }
    38 }
    View Code
    Source
  • 相关阅读:
    Java 8新特性探究(九)跟OOM:Permgen说再见吧
    Java 堆内存(Heap)[转]
    hashmap源码
    Java8学习笔记----Lambda表达式 (转)
    双重检查锁定与延迟初始化(转自infoq)
    kvm的live-snapshot
    8.25考试总结
    CF1151FSonya and Informatics
    CF1151div2(Round 553)
    BZOJ3728 PA2014Final Zarowki
  • 原文地址:https://www.cnblogs.com/ERKE/p/3708460.html
Copyright © 2011-2022 走看看