首页 > 其他 > 详细

ACM Longest Repeated Sequence

时间:2014-04-07 12:27:23      阅读:332      评论:0      收藏:0      [点我收藏+]

Description

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?

Input

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

Output

The length of the longest repeated sequence.

Sample Input

5
2 3 2 3 2

Sample Output

2
bubuko.com,布布扣
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0 ; i < n; ++ i)
        cin >> arr[i];
    int len = 0,size = arr.size();
    for(int i = 0; i < size; ++i)
    {
        for(int j = i+1; j < size ; ++j)
        {
            int k = 0;
            while(i+k < j && j+k < size){
                if(arr[i+k] == arr[j+k]){
                    k++;
                }else{
                    break;
                }
            }
            len = max(k,len);
        }
    }
    cout<< len<<endl;
}
bubuko.com,布布扣

 

ACM Longest Repeated Sequence,布布扣,bubuko.com

ACM Longest Repeated Sequence

原文:http://www.cnblogs.com/xiongqiangcs/p/3647496.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!