码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1423(lcis)

时间:2017-08-14 20:07:55      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:时间   name   ring   scanf   eof   logs   string   main   ios   

难受,看了好长时间,两种思想的结合,加了个dp[j]>=dp[tt]看了好长时间

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=500+10;
int a[maxn],b[maxn],dp[maxn];
int t,m,n;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        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++)
        {
            int tt=1;
            for(int j=1; j<=m; j++)
            {
                if(a[i]>b[j]&&dp[j]>=dp[tt]) tt=j;//a[i]>b[j]确保在后面a[i]==b[j]的时候是上升的,dp[j]>=dp[tt]确保处于lcis序列中
                if(a[i]==b[j]) dp[j]=dp[tt]+1;
            }
        }
        int maxi=0;
        for(int i=1; i<=m; i++)
            maxi=max(maxi,dp[i]);
        printf("%d\n",maxi);
        if(t) printf("\n");
    }
    return 0;
}

 

hdu 1423(lcis)

标签:时间   name   ring   scanf   eof   logs   string   main   ios   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/7359701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!