zoukankan      html  css  js  c++  java
  • 第一轮 D

    Virus
    Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
    Submit Status

    Description
    Download as PDF

    Virus

    We have a log file, which is a sequence of recorded events. Naturally, the timestamps are strictly increasing.

    However, it is infected by a virus, so random records are inserted (but the order of original events is preserved). The backup log file is also infected, but since the virus is making changes randomly, the two logs are now different.

    Given the two infected logs, your task is to find the longest possible original log file. Note that there might be duplicated timestamps in an infected log, but the original log file will not have duplicated timestamps.

    Input
    The first line contains T ( T$ le$100), the number of test cases. Each of the following lines contains two lines, describing the two logs in the same format. Each log starts with an integer n ( 1$ le$n$ le$1000), the number of events in the log, which is followed by n positive integers not greater than 100,000, the timestamps of the events, in the same order as they appear in the log.

    Output
    For each test case, print the number of events in the longest possible original log file.

    Sample Input

    1
    9 1 4 2 6 3 8 5 9 1
    6 2 7 6 3 5 1

    Sample Output

    3

    最长公共子序列匹配

    /*************************************************************************
    	> File Name: e.cpp
    	> Author:yuan 
    	> Mail: 
    	> Created Time: 2014年11月09日 星期日 16时37分18秒
     ************************************************************************/
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int a[1007],b[1007],dp[1007];
    int t,n,m;
    int main()
    {
        scanf("%d",&t);
        while(t--){
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(dp,0,sizeof(dp));
            scanf("%d",&n);
            for(int i=0;i<n;i++) scanf("%d",&a[i]);
            scanf("%d",&m);
            for(int i=0;i<m;i++) scanf("%d",&b[i]);
            for(int i=0;i<n;i++)
            {
                int MAX=0;
                for(int j=0;j<m;j++)
                {
                    
                    if(a[i]==b[j]){
                        dp[j]=MAX+1;
                    }
                    if(a[i]>b[j]&&MAX<dp[j]){
                        MAX=dp[j];
                    }
                }
            }
            int ans=0;
            for(int i=0;i<m;i++)
               ans=max(ans,dp[i]);
            printf("%d
    ",ans);
        }
        return 0;
    }
    



  • 相关阅读:
    全局与本地游标演示.sql
    二进制文件存取示例(TSQL)
    QML与c++交互学习笔记(八) qt c++直接调用QML中的函数, 直接设置属性
    Android 和 Chrome OS 融合的可能性
    Poang,基于Node.js的自动化测试范例
    ADO.NET 4.5中的异步与流特性
    Windows 8 应用前瞻
    Robot Framework作者建议如何选择自动化测试框架
    ROLLUP实现的分级汇总示例(定义各汇总列标题)
    备份指定表到另一数据库.sql
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254393.html
Copyright © 2011-2022 走看看