2024Regular Words

2024   Regular Words

题目描述

Consider words of length 3n over alphabet {A, B, C} . Denote the number of occurences of A in a word a as A(a) , analogously let the number of occurences of B be denoted as B(a), and the number of occurenced of C as C(a) .

Let us call the word w regular if the following conditions are satisfied:

  • A(w)=B(w)=C(w) ;
  • if c is a prefix of w , then A(c)>= B(c) >= C(c) .

For example, if n = 2 there are 5 regular words: AABBCC , AABCBC , ABABCC , ABACBC and ABCABC .

Regular words in some sense generalize regular brackets sequences (if we consider two-letter alphabet and put similar conditions on regular words, they represent regular brackets sequences).

Given n , find the number of regular words.

输入格式:

There are mutiple cases in the input file.

Each case contains n (0 <= n <= 60 ).

There is an empty line after each case.

输出格式:

Output the number of regular words of length 3n .

There should be am empty line after each case.

输入样例 复制
2

3
输出样例 复制
5

42

说明

2
2
通过提交
时空限制2000ms/64mb
题目来源Andrew Stankevich's Contest #10
评测方式在线评测
题目类型
难        度