HDU reproduce the race of 2019CCPC- Jiangxi game: 1004 Wave

Problem Description
Avin is studying series. A series is called "wave" if the following conditions are satisfied:
1) It contains at least two elements;
2) All elements at odd positions are the same;
3) All elements at even positions are the same;
4) Elements at odd positions are NOT the same as the elements at even positions.
You are given a series with length n. Avin asks you to find the longest "wave" subseries. A subseries is a subsequence of a series.
Input
The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a "wave" subseries.
Output
Print the length of the longest "wave" subseries.
Sample Input
5 3 1 2 1 3 2
Sample Output
4
The meaning of problems
To a sequence of integers n, is an integer ranging from 1 ~ c, seeking a sequence number satisfying the same even bit, odd bit on the same numbers, and the numbers of different parity bits.
Output length of the longest sequence to meet the requirements.
answer
The meaning of the questions found Qiuzi only two sequence numbers, sequence coverage is only 1 ~ c (1 ≤ c ≤ 100), two numbers may be enumerated, pairwise matching, extracted from the original sequence of two sequence of numbers, the sequences adjacent to identical elements and an element.
The (211,122) -> (212) the combined sequence length with the longest length of the element can be composed of two energy sequence, complete enumeration of all combinations of numbers obtained after the longest length is also desired .
Code
#include<bits/stdc++.h>
using namespace std;
int n,m;
typedef pair<int,int> p;
vector<p> G[105];
int cmp(p a,p b)
{
    return a.first<b.first;
}
int main()
{
     scanf("%d%d",&n,&m);
     for(int i=1;i<=n;i++)
     {
         int x;
         scanf("%d",&x);
         G[x].push_back(p(i,x));
     }
     int maxn=0;
     for(int i=1;i<=m;i++)
     {
         for(int j=i+1;j<=m;j++)
         {
             if(G[i].size()&&G[j].size())
             {
                vector<p> v;
                 for(int z=0;z<G[i].size();z++)
                 {
                     v.push_back(G[i][z]);
                 }
                 for(int z=0;z<G[j].size();z++)
                 {
                     v.push_back(G[j][z]);
                 }
                 sort(v.begin(),v.end(),cmp);
                 int sum=0,flag;
                 for(int z=0;z<v.size();z++)
                 {
                     if(z==0)sum++,flag=v[z].second;
                     else if(v[z].second!=flag)sum++,flag=v[z].second;
                 }
                 maxn=max(maxn,sum);
             }
         }
     }
     printf("%d\n",maxn);
}
View Code

 Code timeout edge, sweat! !

 
 

Guess you like

Origin www.cnblogs.com/llhsbg/p/11222276.html