package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_2084 { public static void main(String[] args) { BigInteger catalan[] = new BigInteger[102]; catalan[1] = new BigInteger("1"); BigInteger one = new Big…
看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1   h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)   打表172MS import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new S…
卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… 此题就是第4个样例,是裸卡特兰数,但是这里牵扯的大数,可以使用java的大数类解决,但是我这里使用高精度乘法和除法模拟的(主要是java不会). 此处的递推式为H[1] = 1:H[n] = H[n-1]*(4*n-2)/(n+1){n>=2}:代码如下: 需要注意输出的形式,我这里的进制是100…
卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int i; __int64 jw=; ;i>=;i--) { jw=jw+a[i]*b; a[i]=jw%base; jw=jw/base; } } void div(__int64 a[],int len,int b) { int i; __int64 jw=; ;i<lenth;i++) { jw…
POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * source : POJ 2084 * algorithm: Catalan数+高精度 * ***************************************/ import java.io.*; import java.math.*; import java.util.*; publ…
option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" style="">题目链接:uva 1478 - Delta Wave 题目大意:对于每一个位置来说,能够向上,水平,向下.坐标不能位负.每次上下移动最多为1. 给定n问说有多少种不同的图.结果对10100取模. 解题思路:由于最后都要落回y=0的位置,所以上升的次数和下降的次数是同样的…
题意:求n个1,m个-1组成的所有序列中,最大前缀之和. 首先引出这样一个问题:使用n个左括号和m个右括号,组成的合法的括号匹配(每个右括号都有对应的左括号和它匹配)的数目是多少? 1.当n=m时,显然答案为卡特兰数$C_{2n}^{n}-C_{2n}^{n+1}$ 2.当n<m时,无论如何都不合法,答案为0 3.当n>m时,答案为$C_{n+m}^{n}-C_{n+m}^{n+1}$,这是一个推论,证明过程有点抽象,方法是把不合法的方案数等价于从(0,-2)移动到(n+m,n-m)的方案数,…
CARDS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1448   Accepted: 773 Description Alice and Bob have a set of N cards labelled with numbers 1 ... N (so that no two cards have the same label) and a shuffle machine. We assume that N i…
/* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #include <cstdio> using namespace std; typedef long long int64; int64 work(int64 n , int64 k){ if(k > n/2){ k = n-k; } int64 a = 1; int64 b = 1; int…
/* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; char s[60]; int l; bool get(){ int i = l - 1; int j; while(i…