TopcoderArchiveVisit Topcoder
SRM22 Dec 2013
SRM 618

LongWordsDiv1

Problem statement, definition, constraints, and public examples.

Problem Statement

Fox Ciel uses an alphabet that has n letters. She likes all the words that have the following properties:
  1. Equal letters are never consecutive.
  2. There is no subsequence of the form xyxy, where x and y are (not necessarily distinct) letters. Note that a subsequence doesn't have to be contiguous.
  3. There is no longer word with properties 1 and 2.
Examples:
  • Ciel does not like "ABBA" because there are two consecutive 'B's.
  • Ciel does not like "THETOPCODER" because it contains the subsequence "TETE".
  • Ciel does not like "ABACADA" because it contains the subsequence "AAAA". (Note that here x=y='A'.)
  • Ciel does not like "ABCA" because "ABCBA" is longer.
  • If n=1 and the one letter Ciel uses is 'A', then she likes the word "A".
  • If n=2 and the two letters Ciel uses are 'A' and 'B', then she likes the words "ABA" and "BAB".
Given the int n, compute and return the number of words Ciel likes, modulo 1,000,000,007.

Definition

Class:
LongWordsDiv1
Method:
count
Parameters:
int
Returns:
int
Method signature:
int count(int n)
(be sure your method is public)

Constraints

  • n will be between 1 and 5000, inclusive.

Examples

  1. 1
    Returns: 1
    The only word Ciel likes is "A" (assuming 'A' is the only letter in the alphabet).
  2. 2
    Returns: 2
    The words Ciel likes are "ABA" and "BAB".
  3. 5
    Returns: 1080
  4. 100
    Returns: 486425238
    Don't forget to compute the answer modulo 1,000,000,007.
Back to all problems