第一轮 D
来源:互联网 发布:linux中国开源社区 编辑:程序博客网 时间:2024/04/30 18:35
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
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\n",ans); } return 0;}
0 0
- 第一轮 D
- 第一轮 A
- 第一轮 B
- 第一轮 C
- 第一轮 E
- 第一轮 F
- 第一轮 H
- 第一轮 I
- 第一轮 K
- 第一轮 L
- 第一轮 M
- 第一轮 J
- 考研数学第一轮复习
- 第一轮训练总结
- Panasas第一轮面试题
- Bootstrap3学习第一轮(入门)
- 记JSOI2015第一轮
- Zenefits 第一轮编程题
- Linux及Arm-Linux程序开发笔记(零基础入门篇)
- 通过Http协议获取JSON
- Cocos2D IOS 环境搭建
- 数学之美系列二十二:由电视剧《暗算》所想到的 — 谈谈密码学的数学原理
- SlidingPanelLayout与ViewPager滑动冲突的解决方法
- 第一轮 D
- 安装oracle时出现不满足256色的错误解决方法
- 教你怎么使用apilication—纪念火影-->影子模仿术
- 小马哥-----高仿华为荣耀3c 6572芯片详细拆机 主板图 开 真假机鉴别
- Diverse Permutation - CodeForces 482 A 水题
- 树的最近公共祖先——LCA poj1330 hdu2586
- ubuntu下编译java程序
- 就从这里出发
- android Bound Service使用:使用Message类绑定服务