裸的卡特兰数

C++
#include<iostream>
#include<cstdio>
using namespace std;
#define base 10000
#define len 100
void multiply(int a[],int max,int b)
{
int i,array=;
for(i=max-;i>=;i--)
{
array+=b*a[i];
a[i]=array%base;
array/=base; }
} void divide(int a[],int max,int b)
{
int i,div=;
for(i=;i<max;i++)
{
div=div*base+a[i];
a[i]=div/b;
div%=b;
}
} int main()
{
int n,i;
int a[][len];
memset(a[],,len*sizeof(int));
for(i=,a[][len-]=;i<;i++)
{
memcpy(a[i],a[i-],len*sizeof(int));
multiply(a[i],len,*i-);
divide(a[i],len,i+);
}
while(scanf("%d",&n)!=EOF)
{
for(i=;i<len&&a[n][i]==;i++);
printf("%d",a[n][i++]);
for(;i<len;i++)
{
printf("%04d",a[n][i]);
}
printf("\n");
}
return ;
}
pascal
const
modnum=;
type
arraytype=array[..] of longint;
var
s:string;
i,j,l,m,n,le:longint;
h:arraytype;
procedure mul(var h:arraytype; k:longint);
var
j:longint;
begin
for j:= to le do h[j]:=h[j]*k;
for j:= to le- do
begin
h[j+]:=h[j+]+h[j] div modnum;
h[j]:=h[j] mod modnum;
end;
while h[le]>modnum do begin
inc(le);
h[le]:=h[le-] div modnum;
h[le-]:=h[le-] mod modnum;
end;
end;
procedure devide(var h:arraytype; k:longint);
var
d,o,r,i:longint;
begin
r:=;
for i:=le downto do
begin
d:=modnum*r+h[i];
h[i]:=d div k;
r:=d mod k;
end;
end;
begin
readln(n);
h[]:=;
for i:= to n do
begin
mul(h,i+n); devide(h,i);
end;
devide(h,n+);
while h[le]= do dec(le);
write(h[le]);
for i:=le- downto do
begin
str(h[i],s);
while length(s)< do s:=''+s;
write(s);
end;
end.

HDU 1130 How Many Trees?的更多相关文章

  1. HDU——1130 How Many Trees?

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. hdu 1130 How Many Trees?(Catalan数)

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu 1130 How Many Trees? 【卡特兰数】

    题目 题意:给你一个数字n,问你将1~n这n个数字,可以组成多少棵不同的二叉搜索树. 1,2,5,14--根据输出中的规律可以看出这是一个卡特兰数的序列.于是代用卡特兰数中的一个递推式: 因为输入可取 ...

  4. HDU ACM 1134 Game of Connections / 1130 How Many Trees?(卡特兰数)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1134 [解题背景]这题不会做,自己推公式推了一段时间,将n=3和n=4的情况列出来了,只发现第n项与 ...

  5. hdu 1693 Eat the Trees——插头DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...

  6. hdu 1130,hdu 1131(卡特兰数,大数)

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. HDU 1392 Surround the Trees(凸包入门)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  9. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

随机推荐

  1. Deep Learning(深度学习)学习笔记整理系列之(七)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  2. VS2013无法链接到TFS (转)

    VS2013无法链接到TFS(Visual studio online),错误TF31001,TF31002   TF31002: Unable to connect to VisualStudio ...

  3. C - 下沙小面的(2)

    C – 下沙小面的(2)Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDes ...

  4. 使用Docker官方的Django包【转】

    官方Django docker,并没有安装Django 所以需要 在requirements.txt中配置Django 具体安装流程可以参考:http://www.logme.cn/blog/51/u ...

  5. 在zendstudio上配置SVN

    本文介绍zendstudio结合SVN的使用方法. 一.部署svn服务器 直接安装用svn软件,配置太过麻烦,用户和版本库.权限管理不太方便.推荐使用CollabNetSubversionEdge.以 ...

  6. 一个关于css3背景透明的例子

    大家都知道使用opacity调节透明度不仅是背景透明了而且选择区域的文字也跟着透明了, 这是我们不想要的效果,于是强大的css3便有了只让背景透明的功能 那就是background:rgba(0,0, ...

  7. [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  8. MVC进阶之路:依赖注入(Di)和Ninject

    MVC进阶之路:依赖注入(Di)和Ninject 0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类, ...

  9. Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本

    说明:  1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...

  10. PCB打样镀层问题

    现在大部分pcb打样所用PCB板一般有锡板和金板之分(一般根据客户要求和产品特 性选择),那么它们有什么区别呢?现在我将他们的区别作比较如下: 1. 从成本方面来说,锡板价格低,金板价格高. 2. 从 ...