链接:http://acm.hdu.edu.cn/showproblem.php?pid=1502

思路:当只有两个数时,可以用卡特兰数做,当三个数时,没想到卡特兰数的做法。可以使用动态规划。

状态转移方程如下:

dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k] + dp[i][j][k - 1]

代码如下:

import java.math.BigInteger;
import java.util.Scanner;
public class Main{ public static void main(String[] args){
Scanner cin =new Scanner(System.in);
BigInteger dp[][][] = new BigInteger[61][61][61];
dp[0][0][0] = BigInteger.ZERO;
for(int i = 0; i < 2; i++){
for(int j = 0; j <= i; j++){
for(int k = 0; k <= j; k++){
dp[i][j][k] = BigInteger.ONE;
}
}
} int n;
while(cin.hasNext()){
n = cin.nextInt();
for(int i = 2; i <= n ; i++){
for(int j = 0; j <=i; j++){
for(int k = 0; k <= j; k++){
dp[i][j][k] = BigInteger.ZERO;
if(i - 1 >= j){
dp[i][j][k] = dp[i][j][k].add(dp[i - 1][j][k]);
}
if(j - 1 >= k){
dp[i][j][k] = dp[i][j][k].add(dp[i][j - 1][k]);
}
if(k - 1 >= 0){
dp[i][j][k] = dp[i][j][k].add(dp[i][j][k - 1]);
}
}
}
}
System.out.println(dp[n][n][n]);
System.out.println();
}
}
}

HDU1502 Regular Words的更多相关文章

  1. HDU1502 Regular Words DP+大数

    要是c语言可以和java一样写大数就好了,或者我会写重载就好了,最后还是只能暴力一把. 开始写的记忆化搜索,然而n=10就超过LL了 #include<cstdio> #include&l ...

  2. 刷题总结——regular words(hdu1502 dp+高精度加法+压位)

    题目: Problem Description Consider words of length 3n over alphabet {A, B, C} . Denote the number of o ...

  3. [LeetCode] Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  4. MongoVUE1.6.9破解启动提示System.ArgumentException: 字体“Courier New”不支持样式“Regular”

    用MongoVUE,发现报错,报错信息如下: System.ArgumentException: 字体"Courier New"不支持样式"Regular". ...

  5. myeclipse中导入js报如下错误Syntax error on token "Invalid Regular Expression Options", no accurate correc

    今天在使用bootstrap的时候引入的js文件出现错误Syntax error on token "Invalid Regular Expression Options", no ...

  6. [LeetCode] 10. Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...

  7. No.010:Regular Expression Matching

    问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...

  8. scp报错:not a regular file,解决方法:加参数 -r

    命令:scp  -P1234  /data/aa   root@192.0.0..0:/data 文件结构:/data/aa/yearmonth=2015-09 报错:not a regular fi ...

  9. Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

随机推荐

  1. python中单元测试/数据库预处理的技巧

    假设文件结构: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py python -m 你 ...

  2. django 添加动态表格的方法

    传统方法(基于方法的视图):http://stellarchariot.com/blog/2011/02/dynamically-add-form-to-formset-using-javascrip ...

  3. atom 折腾记(转载的)

    http://www.bkjia.com/webzh/999078.html

  4. Unity Assets目录下的特殊文件夹名称

    1.隐藏文件夹以.开头的文件夹会被Unity忽略.在这种文件夹中的资源不会被导入,脚本不会被编译.也不会出现在Project视图中.2.Standard Assets在这个文件夹中的脚本最先被编译.这 ...

  5. 配置ubuntu虚拟机备忘

    #1配置minicom sudo minicom -s sudo minicom -w #1.配置网络,嵌入机的ip地址 ifconfig eth0 10.5.52.202 #2.挂载文件,把虚拟主机 ...

  6. codeforces 425C Sereja and Two Sequences(DP)

    题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...

  7. 重写Equals为什么要同时重写GetHashCode

    .NET程序员都知道,如果我们重写一个类的Equals方法而没有重写GetHashCode,则VS会提示警告 :“***”重写 Object.Equals(object o)但不重写 Object.G ...

  8. Android仿快递 物流时间轴 的代码实现

    首先,这篇参考了别人的代码.根据自己的项目需求简单改造了一下,效果图如下 xml:代码 <?xml version="1.0" encoding="utf-8&qu ...

  9. 【gsl】生成随机数

    来自:http://hsxqwanting.blog.163.com/blog/static/16945437201301042830815/ 使用GSL生成随机数时的三个步骤:    (1)gsl_ ...

  10. 【python】classmethod & staticmethod 区别

    来源:http://blog.csdn.net/carolzhang8406/article/details/6856817 其他参考: http://blog.csdn.net/lovingprin ...