Meaning
Gives a string of the array of suffixes after the sort of SA array, allowing you to construct a string so that the prefix array sa array and the given SA array, ask you at least how many different characters to construct the string.
Analysis:
Understanding suffix array: sa[], rank[], height[] meaning.
Suppose there are two suffixes A and B, and if a<b, there are two things that can be satisfied:
①A[0]<B[0]
②a[0]=b[0], and a suffix array starting with a[1 < A suffix array starting with b[1]
In order to ensure that the type of characters used is the least, the first choice of the first ② of the situation to consider, if the ② is not satisfied, according to ① to construct.
Specific implementation code:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
# Include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
Class SuffixArrayDiv1 {public
:
int minimalcharacters (vector <int>);
int rank[55];
int suffixarraydiv1::minimalcharacters (vector <int> SA) {
int sz=sa.size ();
for (int i=0;i<sz;i++)
{
rank[sa[i]]=i
}
Rank[sz]=-1;
int Ans=1;
for (int i=0;i<sz-1;i++)
{
if (rank[sa[i]+1]>rank[sa[i+1]+1]) ans++;
}
return ans;
}
<%:testing-code%>
//powered by [Kawigiedit] 2.0!