CSU 1120 virus (Classic template example: Maximum public increment subsequence)

Source: Internet
Author: User

1120: Virus time limit:3 Sec Memory limit:128 MB
submit:390 solved:153
[Submit] [Status] [Web Board] Descriptionyou have a log file that contains detailed information about the various system events. Naturally, the timestamps of events are arranged in a strictly ascending order (no two events occur at exactly the same time). Unfortunately, your system is infected with a virus, and the log files are mixed with random pseudo-events generated by the virus (but the relative order of real events remains the same). The backup log file is also infected, but the primary log files and backup log files may become different after the infection due to the random infection method used by the virus. give the infected master log and backup log to find the maximum possible length of the real event sequence. InputEnter the number of first behavior Data group T (t<=100). Each set of data contains two lines that describe the primary and backup logs after the infection. Each log file is in the same format as an integer n (1<=n<=1000) (representing the total number of events after the infection) and n a positive integer not exceeding 100,000 (the timestamp of each event after the infection). Note that after an infection, an event with exactly the same timestamp may occur. Output

For each set of data, the maximum possible length of the real event sequence is output.

Sample Input
19 1 4 2 6 3 8 5 9 16 2 7 6 3 5 1
Sample Output
3 compared to the monotonically increasing, the longest common subsequence, this problem will combine the two, very classic example. 
1#include <iostream>2#include <cstdio>3#include <string.h>4#include <algorithm>5 using namespacestd;6 Const intmaxn=1005;7 intdp[maxn],a[maxn],b[maxn],n,m;8 intLICs ()9 {Ten     intI,j,max; OneMemset (DP,0,sizeof(DP)); A      for(i=1; i<=n;i++) -     { -max=0; the          for(j=1; j<=m;j++) -         { -             if(A[i]>b[j] && max<Dp[j]) -MAX =Dp[j]; +             if(a[i]==B[j]) -dp[j]=max+1; +         } A     } atmax=0; -      for(i=1; i<=m;i++) -         if(max<Dp[i]) -max=Dp[i]; -     returnMAX; - } in  - intMain () to { +     intt,i; -scanf"%d",&T); the      while(t--) *     { $scanf"%d",&n);Panax Notoginseng          for(i =1; i<=n;i++) -scanf"%d",&a[i]); thescanf"%d",&m); +          for(i =1; i<=m;i++) Ascanf"%d",&b[i]); theprintf"%d\n", LICs ()); +     } -     return 0; $}

CSU 1120 virus (Classic template example: Maximum public increment subsequence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.