HDU1502 Regular Words
链接: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的更多相关文章
- HDU1502 Regular Words DP+大数
要是c语言可以和java一样写大数就好了,或者我会写重载就好了,最后还是只能暴力一把. 开始写的记忆化搜索,然而n=10就超过LL了 #include<cstdio> #include&l ...
- 刷题总结——regular words(hdu1502 dp+高精度加法+压位)
题目: Problem Description Consider words of length 3n over alphabet {A, B, C} . Denote the number of o ...
- [LeetCode] Regular Expression Matching 正则表达式匹配
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- MongoVUE1.6.9破解启动提示System.ArgumentException: 字体“Courier New”不支持样式“Regular”
用MongoVUE,发现报错,报错信息如下: System.ArgumentException: 字体"Courier New"不支持样式"Regular". ...
- myeclipse中导入js报如下错误Syntax error on token "Invalid Regular Expression Options", no accurate correc
今天在使用bootstrap的时候引入的js文件出现错误Syntax error on token "Invalid Regular Expression Options", no ...
- [LeetCode] 10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...
- No.010:Regular Expression Matching
问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...
- 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 ...
- Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
随机推荐
- 保存字符串到手机SDcard为txt文件
try { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sdCardDir ...
- 【leetcode】Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...
- CEF3开发者系列之进程和线程
CEF3是一个多进程架构框架,如果有了解过chromium的进程架构的,那么就很容易了解CEF3的多进程了.打开CEF3源代码中发布的cefclient实例,如果打开的页面带有flash或者其他插件. ...
- codecademy-command line_filesystem
$:shell prompt (命令提示符) In the terminal, first you see $. This is called a shell prompt. It appears w ...
- ios 把已经点击过的UILocalNotification 从系统的通知中心现实中移除
在ios7 上一个uilocalnotification在中心现实后,点击该消息,程序被唤醒了,但是该通知没有被移除.用了以下的代码后可以解决这个问题 UIApplication.sh ...
- Nginx反向代理到Tomcat服务器
在实际生产中,Tomcat服务器一般不单独使用在项目中,对于静态资源的响应Nginx表现的比较好,另外由于nginx是专门用于反向代理的服务器,所以很容易实现将java的请求转发到后端交给tomcat ...
- ACM/ICPC 之 最短路-Floyd+SPFA(BFS)+DP(ZOJ1232)
这是一道非常好的题目,融合了很多知识点. ZOJ1232-Adventrue of Super Mario 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...
- FFMpeg ver 20160213-git-588e2e3 滤镜中英文对照
1 FFMpeg ver 20160213-git-588e2e3 滤镜中英文对照 2016.02.18 by 1CM 2 T.. = Timeline support 3 支持时间轴 4 .S. = ...
- WebLogic部署
1.抓取解压WAR包,放在相应目录下 2.登录部署,激活 http://jingyan.baidu.com/article/c74d6000650d470f6b595d72.html Linux环境中 ...
- Mathematics:Dead Fraction(POJ 1930)
消失了的分式 题目大意:某个人在赶论文,需要把里面有些写成小数的数字化为分式,这些小数是无限循环小数(有理数),要你找对应的分母最小的那个分式(也就是从哪里开始循环并不知道). 一开始我也是蒙了,这尼 ...