zoukankan      html  css  js  c++  java
  • HDU1423 最长上升公共子序列

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 const int maxn = 205;
     6 int a[ maxn ],b[ maxn ],dp[ maxn ];
     7 int s[ maxn ];
     8 int LCIS( int a[],int b[],int lena,int lenb ){
     9     /*
    10     dp[i]:表示当b字符串到了第i个时,与a[]中的符合的最长公共上升子序列
    11     */
    12     memset( dp,0,sizeof( dp ) );
    13     dp[ 0 ]=-1;
    14     for( int i=1;i<=lena;i++ ){
    15         int locate = 0;
    16         for( int j=1;j<=lenb;j++ ){
    17             if( a[i]>b[j]&&dp[ locate ]<dp[ j ] ){
    18                 locate = j;
    19             }
    20             if( a[i]==b[j] ){
    21                 dp[ j ]=dp[ locate ]>=0?(dp[ locate ]+1):1;
    22             }
    23         }//当a[i]时,遍历b中的dp最大的那个
    24     }
    25     int ans = 0;
    26     for( int i = 1;i <= lenb; i++ )
    27         ans = max( ans,dp[ i ] );
    28     return ans;
    29 }
    30 
    31 int main(){
    32     int ca;
    33     scanf("%d",&ca);
    34     while( ca-- ){
    35         int n;
    36         scanf("%d",&n);
    37         for( int i=1;i<=n;i++ )
    38             scanf("%d",&a[ i ]);
    39         int m;
    40         scanf("%d",&m);
    41         for( int i=1;i<=m;i++ )
    42             scanf("%d",&b[ i ]);
    43         printf("%d\n",LCIS( a,b,n,m ));
    44         if( ca ) printf("\n");
    45     }
    46     return 0;
    47 }
    keep moving...
  • 相关阅读:
    python函数续
    模拟数据库查询操作
    文件处理
    字符编码
    python函数
    ACM-ICPC 2018 南京赛区网络预赛Skr
    bzoj3676: [Apio2014]回文串 pam
    Wannafly挑战赛23B游戏
    bzoj4804: 欧拉心算 欧拉筛
    bzoj3884: 上帝与集合的正确用法 扩展欧拉定理
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2976416.html
Copyright © 2011-2022 走看看