UVA12511 VirusLCIS
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA12511 VirusLCIS相关的知识,希望对你有一定的参考价值。
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 ≤ 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 ≤ n ≤ 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
问题链接:UVA12511 Virus
问题简述:(略)
问题分析:最长公共上升子序列问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA12511 Virus */
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int a[N], b[N], lcis[N];
int main()
{
int t, n, m;
scanf("%d", &t);
while (t--) {
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]);
memset(lcis, 0, sizeof lcis);
for (int i = 0; i < n; i++) {
int t = 0;
for (int j = 0; j < m; j++) {
if (a[i] == b[j] && lcis[j] < t + 1)
lcis[j] = t + 1;
if (a[i] > b[j] && lcis[j] > t)
t = lcis[j];
}
}
int ans = 0;
for (int i = 0; i < m; i++)
if (lcis[i] > ans) ans = lcis[i];
printf("%d\\n", ans);
}
return 0;
}
以上是关于UVA12511 VirusLCIS的主要内容,如果未能解决你的问题,请参考以下文章