您的位置:首页 > 其它

hdu1502 Regular Words--DP&大数问题

2016-03-28 22:41 302 查看
原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=1502
一:原题内容

[align=left]Problem Description[/align]
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.
 

[align=left]Input[/align]
There are mutiple cases in the input file.

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

There is an empty line after each case.
 

[align=left]Output[/align]
Output the number of regular words of length 3n .

There should be am empty line after each case.
 

[align=left]Sample Input[/align]

2

3

 

[align=left]Sample Output[/align]

5

42

二:分析理解

http://www.tuicool.com/articles/ENVn6z  和 
http://blog.csdn.net/jiang199235jiangjj/article/details/7452389
三:AC代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: