TopCoder srm630,div1,500, suffix array __topcoder

Source: Internet
Author: User

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!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.