ZOJ 2604 Little Brackets DP
来源:互联网 发布:sql insert update 编辑:程序博客网 时间:2024/05/16 17:27
DP:
- 边界条件:dp[0][j] = 1
- 递推公式:dp[i][j] = sum{dp[i-k][j] * dp[k-1][j-1] | 0<k≤i}
Consider all regular bracket sequences with one type of brackets. Let us call the depth of the sequence the maximal difference between the number of opening and the number of closing brackets in a sequence prefix. For example, the depth of the sequence "()()(())" is 2, and the depth of "((()(())()))" is 4.
Find out the number of regular bracket sequences with n opening brackets that have the depth equal to k. For example, for n = 3 and k = 2 there are three such sequences: "()(())", "(()())", "(())()".
Input
Input file contains several test cases. Each test case is described with n and k (1 <= k <= n <= 50).
Last testcase is followed by two zeroes. They should not be processed.
Output
For each testcase output the number of regular bracket sequences with n opening brackets that have the depth equal to k.
Separate output for different testcases by a blank line. Adhere to the format of the sample output.
Sample Input
3 237 230 0
Sample Output
Case 1: 3Case 2: 203685956218528
Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #7
import java.util.*;import java.math.*;public class Main{ static BigInteger dp[][] = new BigInteger[55][55]; static void INIT() { for(int i=0;i<55;i++) for(int j=0;j<55;j++) dp[i][j]=BigInteger.ZERO; for(int i=0;i<55;i++) dp[0][i]=BigInteger.ONE; for(int i=1;i<=50;i++) { for(int j=1;j<=50;j++) { for(int k=1;k<=i;k++) { dp[i][j]=dp[i][j].add(dp[i-k][j].multiply(dp[k-1][j-1])); } } } } public static void main(String[] args) { Scanner in = new Scanner(System.in); INIT(); int cas=1; boolean pr = false; while(in.hasNext()) { int n=in.nextInt(),k=in.nextInt(); if(n==0&&k==0) break; if(pr) System.out.println(""); System.out.println("Case "+(cas++)+": "+dp[n][k].subtract(dp[n][k-1])); pr=true; } }}
- ZOJ 2604 Little Brackets DP
- ZOJ 2604 Little Brackets(高精度+dp)
- ZOJ:2604 Little Brackets
- zoj 2604 Little Brackets(动态规划+递推+java)
- ZOJ 1463 POJ 1141 Brackets Sequence (区间DP) #by Plato
- ZJU 2604 Little Brackets - 动态规划 Catalan数变形
- ZOJ 1463 Brackets Sequence
- zoj 2704 Brackets
- [ZOJ 1463] Brackets Sequence
- zoj 2704 Brackets
- zoj 2704 Brackets
- zoj 2704 Brackets
- {DP!}ZOJ 2604
- DP之Brackets Sequence
- POJ2955 Brackets (DP)
- DP poj 2955 Brackets
- POJ1141--Brackets Sequence--DP
- POJ2955:Brackets(区间DP)
- 8uc4 9oQbmlongchamp q2wg JlQ
- 在字符串中删除指定字符
- codecomb 2100【警察叔叔就是这个人!】
- C++拷贝函数的小结,关于变量的作用域等---ShinePans
- 今天实验室的上课心得
- ZOJ 2604 Little Brackets DP
- SQL 存储过程
- UISegmentControl控件的简单使用
- 纪念acm 2014 牡丹江邀请赛
- hdu 4983 欧拉函数
- next_permutation函数
- hdu 4472 dp
- 第五章 5.6.3节练习
- C#实现全局快捷键(系统热键)响应(转)