Regular Words

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2102    Accepted Submission(s): 825

Problem 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.

 
Input
There are mutiple cases in the input file.

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.

 
Sample Input
2
3
 
Sample Output
5
42
 
还是看题解做的,蓝瘦。。。
dp[i][j][k][100]; i这维表示a的个数,j这维表示b的个数,k这维表示c的个数。
dp过程中需要用大数加法。
 
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; void add(char A[],char B[],char C[])
{
int a=;
int len1=strlen(A);
int len2=strlen(B);
int wei=;
while(a<len1&&a<len2)
{
int sum=A[a]+B[a]-''-''+wei;
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
while(a<len1)
{
int sum=A[a]+wei-'';
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
while(a<len2)
{
int sum=B[a]+wei-'';
wei=;
if(sum>)
{
wei++;
sum-=;
}
C[a]=sum+'';
a++;
}
if(wei>)
C[a++]='';
C[a]='\0';
} char dp[][][][]; int main()
{
char A[],B[],C[];
for(int i=; i<=; i++)
for(int j=; j<=; j++)
for(int k=; k<=; k++)
strcpy(dp[i][j][k],"");
strcpy(dp[][][],""); for(int i=; i<=; i++)
for(int j=; j<=; j++)
for(int k=; k<=; k++)
{
if(i>=j&&j>=k)
{
add(dp[i-][j][k],dp[i][j-][k],dp[i][j][k]);
add(dp[i][j][k],dp[i][j][k-],dp[i][j][k]);
}
}
int n;
while(scanf("%d",&n)!=EOF)
{
int len=strlen(dp[n][n][n]);
char res[];
for(int i=len-;i>=;i--)
res[len-i-]=dp[n][n][n][i];
res[len]='\0';
printf("%s\n\n",res);
//getchar();
}
return ;
}
 

HDU_1502_dp的更多相关文章

随机推荐

  1. ubuntu18.04安装magento2

    magento2更新很快,使用的技术都是很前沿的,国内外的技术帖子又很少,安装的时候难免会遇到各种各样的问题.我们单位因为是外资,总部在国外,最近在自主开发电商网站,开发语言是php,首选了magen ...

  2. Alcatel OmniSwitch 重置密码

    OmniSwitch 6250重置密码 Press s to STOP AT MINIBOOT... [Miniboot]->cd "network" value = 0 = ...

  3. JAVA 如何反编译JAR文件

    1 直接的jar文件可以用winrar解压,然后得到class文件,但是这里得到的class文件也是编译过的二进制文件,用传统的文本编辑器无法打开. 2 用XJad这个软件可以反编译Jar文件,直接找 ...

  4. Java基础:初始化和清理

    转载请注明出处:jiq•钦's technical Blog (1) 初始化: 所以假设继承关系为:A导出B再导出C,在创建C对象的情况下的调用顺序是: * (1) A的静态域,B的静态域,C的静态域 ...

  5. cocos2D(七)---- CCScene

    CCScene普通情况是游戏里面的根节点.称之为"场景",执行游戏时须要通过CCDirector启动第一个场景. 当然,游戏略微复杂一点的话.可能会包括非常多个场景,这就涉及到场景 ...

  6. 百度开放云java+tomcat部署web项目-小皇帝詹姆斯

    加入部署 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  7. centos中chfn命令

    功能说明:改变finger指令显示的信息 假设你想改变哪个用户的finger信息,直接chfn username就可以.然后就能够输入一系列的信息 [root@centos Desktop]# chf ...

  8. Java - HashTable、HashMap和LinkedHashMap的区别

    一般情况下,我们用的最多的是HashMap,在Map 中插入.删除和定位元素,HashMap 是最好的选择.但如果您要按自然顺序或自定义顺序遍历键,那么TreeMap会更好.如果需要输出的顺序和输入的 ...

  9. phpexecl 的基本操作

    基本使用方法分三部分:一.引入接口 // PHPExcel_IOFactory require_once dirname(__FILE__).'/Classes/PHPExcel/IOFactory. ...

  10. [Swift通天遁地]九、拔剑吧-(2)在项目中使用大量美观的图标

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...