hdu 1502 Regular Word
来源:互联网 发布:数据新闻能否成为主流 编辑:程序博客网 时间:2024/06/16 00:13
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1502
题目描述:
Description
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.
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.
Input
There are mutiple cases in the input file.
Each case contains n (0 <= n <= 60 ).
There is an empty line after each case.
Each case contains n (0 <= n <= 60 ).
There is an empty line after each case.
Output
Output the number of regular words of length 3n .
There should be am empty line after each case.
There should be am empty line after each case.
Sample Input
23
Sample Output
542
题目大意:
第一行给你一个整数n,代表abc三个字母每个有n个,现在问你有多少种排列方法,使得前任意项都有a的数目>=b的数目>=c的数目
题目分析;
状态转移方程:dp[x][y][z]=dp[x-1][y][z]+dp[x][y-1][z]+dp[x][y][z-1]
Ac代码:
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;char num[65][105],dp[65][65][65][105];void sum(char *a,char *b){ int l1=a[0],l2=b[0],lmax;//a[0],b[0]代表字符串长度 a[0]=lmax=max(l1,l2); for(int i=1;i<=lmax;i++)//高精度 { a[i]+=b[i]; if(a[i]>=10) { a[i+1]++; a[i]%=10; if(i+1>lmax) { a[0]++; lmax++; } } }}void cpy(char *a,char *b){ for(int i=0;i<=b[0];i++) a[i]=b[i];}void LCS(int x,int y,int z){ //状态转移方程 if(x>=1&&x-1>=y&&y>=z) sum(dp[x][y][z],dp[x-1][y][z]); if(y>=1&&x>=y-1&&y-1>=z) sum(dp[x][y][z],dp[x][y-1][z]); if(z>=1&&x>=y&&y>=z-1) sum(dp[x][y][z],dp[x][y][z-1]);}void Init(){ memset(dp,0,sizeof(dp)); dp[0][0][0][0]=1; dp[0][0][0][1]=1; for(int i=1;i<=60;i++) { for(int j=0;j<=i;j++) { for(int k=0;k<=j;k++) { LCS(i,j,k); if(i==j&&j==k) cpy(num[i],dp[i][j][k]); } } }}int main(){ Init(); int n; while(scanf("%d",&n)!=EOF) { for(int i=num[n][0];i>=1;i--) printf("%d",num[n][i]); printf("\n\n"); } return 0;}
0 0
- hdu 1502 Regular Word
- hdu 1502 Regular Words
- hdu 1502 Regular Words
- hdu 1502 Regular Words
- 【DP】HDU-1502 Regular Words
- Hdu 1502 Regular Words (java高精度 + DP)
- hdu 1502 Regular Words_高精度+dp
- HDU 1502 Regular Words(DP + JAVA)
- HDU 1502 Regular Words(大数+dp)
- [HDU 1502][动态规划]Regular Words
- hdu 4033 Regular Polygon
- [HDU]-6055 Regular polygon
- Regular polygon HDU
- hdu-6055-Regular polygon
- Regular polygon HDU 6055
- hdu--6055--Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- Linux安装软件的方式
- 使用Glide加载、缓存图片、Gif、解决背景出现浅绿色、GlideModules冲突
- Android 自定义地图控件 可手指拉伸放大缩小拖动,指定坐标加点加线
- JAVA中对象的赋值与引用
- 国密SM1、SM2、SM3、SM4算法资料大全
- hdu 1502 Regular Word
- python 如何用修饰符打造一个单例
- SDUT OJ 2039数据结构上机实验之二分查找
- Android真机获得root权限修改文件权限
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
- android 打包签名时出现Conversion to Dalvik format failed
- c++ 学习之路 typeid
- Android中如何集成融云SDK单聊
- 极光推送和苹果远程推送