ZOJ 3019 Puzzle
来源:互联网 发布:海岛奇兵震爆数据 编辑:程序博客网 时间:2024/05/17 22:05
For sequences of integers a and b, if you can make the two sequences the same by deleting some elements in a and b, we call the remaining sequence "the common sub sequence". And we call the longest one the LCS.
Now you are given two sequences of integers a and b. You can arrange elements in a and b in any order. You are to calculate the max length of the LCS of each arrangement ofa and b.
Input
Input will consist of multiple test cases. The first line of each case is two integers N(0 < N < 10000), M(0 < M < 10000) indicating the length ofa and b. The second line is N 32-bit signed integers ina. The third line is M 32-bit signed integers in b.
Output
Each case one line. The max length of the LCS of each arrangement of a andb.
Sample Input
5 41 2 3 2 11 4 2 1
Sample Output
3
公共序列最长(乱序)
排序,然后找就行
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define N 100005int a[N],b[N];int main(){ int aa,bb,i; while(~scanf("%d%d",&aa,&bb)) { for(i=0;i<aa;i++) scanf("%d",&a[i]); for(i=0;i<bb;i++) scanf("%d",&b[i]); sort(a,a+aa); sort(b,b+bb); int ans=0; int j=0,temp=0;//temp是重点 for(i=0;i<aa;i++) for(j=temp;j<bb;j++) if(a[i]==b[j]) { ans++; temp=j+1; break; } printf("%d\n",ans); } return 0;}
- zoj 3019 Puzzle
- ZOJ 3019 Puzzle【水】
- zoj 3019 Puzzle
- ZOJ 3019 Puzzle
- zoj 3019 Puzzle
- zoj 3019 Puzzle (4)
- ZOJ Problem Set - 3019 Puzzle
- zoj 3091 Puzzle
- zoj 1602 Multiplication Puzzle
- ZOJ 1602 Multiplication Puzzle
- ZOJ 2610 Puzzle 模拟
- zoj 3814 Sawtooth Puzzle
- zoj 1602 Multiplication Puzzle
- ZOJ 2836 Number Puzzle
- zoj 3019 Puzzle(这个算是贪心吧??)
- ZOJ 1602 Multiplication Puzzle (DP)
- zoj 3541 The Last Puzzle
- ZOJ 3541 The Last Puzzle
- 【安卓篇】四大组件●Service服务介绍及生命周期
- hdu 1016 Prime Ring Problem
- 【CH Round #48 - Streaming #3(NOIP模拟赛Day1)】 题解
- 双WaitForMultipleObjects机制
- 欢聚时代Linux下的主动防御
- ZOJ 3019 Puzzle
- Undefined symbols for architecture i386或者armv7: “_OBJC_CLASS_$_XXX
- 【安卓篇】Android四大组件●Content Provider组件介绍与生命周期
- 13. Java类集 Part 1(类集、Collection接口、List接口、Set接口、SortedSet接口、集合的输出) ----- 学习笔记
- ZOJ 3656 Bit Magic (2-sat 可行性判定)
- Linux下EPoll通信模型简析
- UVa273 - Jack Straws(线段相交,floyd_warshall)
- Android蓝牙开发浅析
- 各种语言在线编译器