卡特兰数。

#include<stdio.h>
#include<string.h>
const __int64 base=;
const int lenth=;
void mul(__int64 a[],int len,int b)
{
int i;
__int64 jw=;
for(i=len-;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=;
for(i=;i<lenth;i++)
{
jw=jw*base+a[i];
a[i]=jw/b;
jw=jw%b;
}
}
int main()
{
int i,j,n;
__int64 a[][];
memset(a[],,sizeof(a[]));
a[][lenth-]=;
for(i=;i<=;i++)
{
memcpy(a[i],a[i-],sizeof(a[]));
mul(a[i],lenth,*i-);
div(a[i],lenth,i+);
}
while(scanf("%d",&n)!=EOF)
{
if(n==-) break;
for(i=;i<lenth&&a[n][i]==;i++);
printf("%I64d",a[n][i++]);
for(;i<lenth;i++)
printf("%0*I64d",,a[n][i]);
printf("\n");
} return ;
}

POJ 2084 Game of Connections的更多相关文章

  1. (组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_2084 ...

  2. POJ 2084 Game of Connections(卡特兰数)

    卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...

  3. POJ 2084 Game of Connections 卡特兰数

    看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1   h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) ( ...

  4. POJ 2084 Catalan数+高精度

    POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...

  5. poj——2084  Game of Connections

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8664   Accepted: 42 ...

  6. POJ 2084 Catalan

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8772   Accepted: 43 ...

  7. POJ 2084

    第一题组合数学题.可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理.(高精度) #include <cstdio> #include & ...

  8. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  9. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. 微信公众号token的asp.net脚本

    老板让我搞一个微信公众号.好吧.前面都很EZ,直到要使用一个token验证服务器的有效性. 看了下文档,大概意思就是微信的服务器用GET请求访问你的服务器. 其中包含了signature,nonce, ...

  2. HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)

    题目 //每次for循环的时候总是会忘记最后一段,真是白痴.... //连续的he的个数 种数 //0 1 //1 1 //2 2 //3 3 //4 5 //5 8 //…… …… //斐波纳契数列 ...

  3. POJ 1936

    #include<iostream> #include<string> using namespace std; int main() { //freopen("ac ...

  4. Linux客户/服务器程序设计范式2——并发服务器(进程池)

    引言 让服务器在启动阶段调用fork创建一个子进程池,通过子进程来处理客户端请求.子进程与父进程之间使用socketpair进行通信(为了方便使用sendmsg与recvmsg,如果使用匿名管道,则无 ...

  5. 李洪强iOS开发之OC[009] -OC无参方法的声明实现和调用

  6. 如何在solution中添加一个test case

    在solution Explorer中右键点击需要添加的folder,选择Add-New Item.也可以选择使用相应Unit Test之类的.Generic Test一般用于创建manual cas ...

  7. 6 tips for recovering from a flop

    6 tips for recovering from a flop职场没有失败:6招走出工作失误阴影"We all make mistakes, if we're going to lear ...

  8. ios开发--一个苹果证书怎么多次使用——导出p12文件

    为什么要导出.p12文件 当我们用大于三个mac设备开发应用时,想要申请新的证书,如果在我们的证书里,包含了3个发布证书,2个开发证书,可以发现再也申请不了开发证书和发布证书了(一般在我们的证书界面中 ...

  9. MySql对空间数据库的支持

    地址: MySQL5.1中文在线API:http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chapter/spatial-extensions-in-mysq ...

  10. 290. Word Pattern

    题目: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ...