http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1120
1120: 病毒
Time Limit: 3 Sec Memory Limit: 128 Mb Submitted: 1194 Solved: 509Description
你有一个日志文件,里面记录着各种系统事件的详细信息。自然的,事件的时间戳按照严格递增顺序排列(不会有两个事件在完全相同的时刻发生)。
遗憾的是,你的系统被病毒感染了,日志文件中混入了病毒生成的随机伪事件(但真实事件的相对顺序保持不变)。备份的日志文件也被感染了,但由于病毒采用的随机感染方法,主日志文件和备份日志文件在感染后可能会变得不一样。
给出被感染的主日志和备份日志,求真实事件序列的最长可能长度。
Input
输入第一行为数据组数T (T<=100)。每组数据包含两行,分别描述感染后的主日志和备份日志。
每个日志文件的格式相同,均为一个整数n (1<=n<=1000)(代表感染后的事件总数)和n 个不超过100,000的正整数(表示感染后各事件的时间戳)。
注意,感染后可能会出现时间戳完全相同的事件。
Output
对于每组数据,输出真实事件序列的最长可能长度。
Sample Input
1 9 1 4 2 6 3 8 5 9 1 6 2 7 6 3 5 1
Sample Output
3
Hint
Source
湖南省第八届大学生计算机程序设计竞赛最长公共子序列我会,最长递增子序列我会,但是合到一块我想了2小时也没想出来,看了题解发现完全想复杂了,这个思想真简单,再给我一天我也做不出来,学到了,还不错
题意:最长公共递增子序列。
思路:学思路看代码吧;
AC代码:(懂了题解后直接打了一遍,没编译直接交,就过了)
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define LL long long
#define eps 1e-8
using namespace std;
const int mod = 1e7+7;
const int INF = 1e8;
const int inf = 0x3f3f3f3f;
const int maxx = 10100;
const int N = 1010;
int n,m;
int a[N],b[N],dp[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
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 num=0;
for(int j=0;j<m;j++)
{
if(a[i]>b[j]&&num<dp[j])
num=dp[j];
if(a[i]==b[j])
dp[j]=num+1;
}
}
int ans=0;
for(int i=0;i<m;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
}