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代码
一:原题内容
[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代码
相关文章推荐
- git版本控制管理的学习(二)——索引探索
- windows客户端开发--使用json11解析json
- POJ 1328(Radar Installation 区间贪心)
- css样式(一)
- windows客户端开发--使用json11解析json
- php练习题:投票
- 复利计算器4.0之再遇JUnit
- CSS选择器
- Leetcode - Reverse Integer
- 面包屑 CSS(合并小图标,减少链接请求数量)
- base64编码长度计算
- APK反编译
- 大学毕业4年-回顾和总结(5)-投资理财方法论
- 大学毕业4年-回顾和总结(5)-投资理财方法论
- yum只下载不安装包
- 求1到n的平方和
- 第五周项目4——长方柱类
- glance镜像元数据
- Android进程优先级部分整理与理解
- c++模板实现双向链表