Longest Repeated Sequence

来源:互联网 发布:vmware12安装mac os x 编辑:程序博客网 时间:2024/05/24 02:57

题目:

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

You are given a sequence of integers, A = a1, a2, ... an. A consecutive subsequence of A (say ai, ai+1 ... aj) is called a "repeated sequence" if it appears more than once in A (there exists some positive k that ai+k = ai, ai+k+1 = ai+1, ... aj+k = aj) and its appearances are not intersected (i + k > j).

Can you find the longest repeated sequence in A?

输入

Line 1: n (1 <= n <= 300), the length of A.
Line 2: the sequence, a1 a2 ... an (0 <= ai <= 100).

输出

The length of the longest repeated sequence.

样例输入
52 3 2 3 2
样例输出
2
算法思想:

将运算中的局部结果保存在一个二维数组mark[][]中,mark[i][j]表示与子序列ai, ai+1 ... aj重复的下个子序列中首个数字的索引,

mark[i][j+1]由mark[i][j]很容易得到。


0 0