SuffixArrayDiv1

传送门

Problem Statement

Suffix number i of a string S is the suffix that starts with the character S[i]. For example, for S="abcde" suffix 0 is "abcde" and suffix 3 is "de". 

The suffix array of a string S is defined as the permutation of suffix numbers that corresponds to their lexicographic order. For example, suppose that S="abca". If we order all suffixes of S lexicographically, we get the following: "a" < "abca" < "bca" < "ca". The corresponding suffix numbers are 3, 0, 1, and 2, in this order. Thus, for this string S the suffix array would be {3, 0, 1, 2}. Note that the length of a suffix array is the same as the length of the original string. 

You are given a  SA: the suffix array of an unknown string. Return the smallest possible number of  different characters in that string.

Definition

Class:
 
SuffixArrayDiv1
Method:
 
minimalCharacters
Parameters:
 
int[]
Returns:
 
int
Method signature:
 
int minimalCharacters(int[] SA)
(be sure your method is public)

Limits

Time limit (s):
 
2.000
Memory limit (MB):
 
256

Notes

- We do not consider any specific alphabet. In particular, it is possible to have more than 26 different letters.
- For any suffix array, there is at least one string with such a suffix array, so the return value is always defined.
- The string A is smaller than a different string B in lexicographic order either if A is a prefix of B, or if there are indices where A and B differ, and for the smallest such index i we have A[i] < B[i].

Constraints

SA will contain between 1 and 50 elements, inclusive.
SA will be a permutation of 0 to | SA|-1, inclusive.

Examples

0)
{3,0,1,2}
Returns: 2
As we saw in the problem statement, the suffix array {3,0,1,2} corresponds to the string "abca". However, there are also other string with the same suffix array. For example, the string "xxyx" also has this property, and contains only two different characters.
1)
{3,2,1,0}
Returns: 1
One optimal string is "aaaa".
2)
{0,1,2,3}
Returns: 2
Here, one optimal string is "aaaz".
3)
{7,4,8,6,1,5,2,9,3,0}
Returns: 4
4)
{0}
Returns: 1
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值