Count the Trees





Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1840    Accepted Submission(s): 1221









Problem Description

Another common social inability is known as ACM (Abnormally Compulsive Meditation). This psychological disorder is somewhat common among programmers. It can be described as the temporary (although frequent) loss of the faculty of speech when the whole power
of the brain is applied to something extremely interesting or challenging. 

Juan is a very gifted programmer, and has a severe case of ACM (he even participated in an ACM world championship a few months ago). Lately, his loved ones are worried about him, because he has found a new exciting problem to exercise his intellectual powers,
and he has been speechless for several weeks now. The problem is the determination of the number of different labeled binary trees that can be built using exactly n different elements. 





For example, given one element A, just one binary tree can be formed (using A as the root of the tree). With two elements, A and B, four different binary trees can be created, as shown in the figure. 





If you are able to provide a solution for this problem, Juan will be able to talk again, and his friends and family will be forever grateful. 





 





Input

The input will consist of several input cases, one per line. Each input case will be specified by the number n ( 1 ≤ n ≤ 100 ) of different elements that must be used to form the trees. A number 0 will mark the end of input and is not to be processed. 

 





Output

For each input case print the number of binary trees that can be built using the n elements, followed by a newline character. 

 





Sample Input

1

2

10

25

0

 





Sample Output

1

4

60949324800

75414671852339208296275849248768000000

 

 

#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

using namespace std;

int h[102][1001];

int main()

{

   int n;

   h[1][0]=1;h[1][1]=1;

   h[2][0]=1;h[2][1]=1;

   for(int i=3;i<=100;i++)

   {

       int temp=0,jin=0;

       for(int j=1;j<=h[i-1][0];j++)

            {

                temp=h[i-1][j]*(4*i-2);

                h[i][j]=temp%10;

                h[i][j+1]=+temp/10;

            }

        int t=h[i-1][0];

       t=h[i][t+1]>0?t+1:t;

       while(h[i][t]>=10)

       {

            h[i][t+1]=h[i][t]/10;

            h[i][t]%=10;

            t++;

       }

       for(int j=t;j>=2;j--)

            {

                temp=h[i][j];

                h[i][j]=temp/(i+1);

                h[i][j-1]+=temp%(i+1)*10;

            }

   }

   for(int i=2;i<=100;i++)

   {

        for(int j=1;j<=i;j++)

              for(int k=1;k<=h[i][0];k++)

                    h[i][k]*=j;

         for(int t=1;t<=h[i][0];t++)

       {

             int temp=h[i][t];

             h[i][t]=temp%10;

             h[i][t+1]+=temp/10;

       }

        int t=h[i-1][0];

       while(h[i][t]>=10)

       {

            h[i][t+1]=h[i][t]/10;

            h[i][t]%=10;

            t++;

       }

        h[i][0]=t;

   }

   while(cin>>n&&n)

   {

         for(int i=h[n][0];i>=1;i--)

            printf("%d",h[n][i]);

         printf("\n");

   }

   return 0;

}

未AC的更多相关文章

  1. 九度OJ 1016 火星A + B 未AC版,整型存储不下

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  2. Poj 1755Triathlon 未Ac,先mark

    地址:http://poj.org/problem?id=1755 题目: Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  3. 字符串[未AC](后缀自动机):HEOI 2016 str

    超级恶心,先后用set维护right,再用主席树维护,全部超时,本地测是AC的.放心,BZOJ上还是1S限制,貌似只有常数优化到一定境界的人才能AC吧. 总之我是精神胜利了哦耶QAQ #include ...

  4. UOJ.87.mx的仙人掌(圆方树 虚树)(未AC)

    题目链接 本代码10分(感觉速度还行..). 建圆方树,预处理一些东西.对询问建虚树. 对于虚树上的圆点直接做:对于方点特判,枚举其所有儿子,如果子节点不在该方点代表的环中,跳到那个点并更新其val, ...

  5. UVA1625Color Lenth(DP+LCS变形 未AC)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/C 紫书P276 res[i][j]表示第一个序列移动i个,第 ...

  6. NOIp 2014 #2 联合权值 Label:图论 !!!未AC

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  7. ZOJ3229 Shoot the Bullet [未AC]

    Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge Gensokyo is a world which exist ...

  8. 2833 奇怪的梦境 未AC

    2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold         题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小 ...

  9. Poj 3057 未AC http://poj.org/showsource?solution_id=15175171

    <span style="font-size:18px;">#include <iostream> #include <cstdio> #inc ...

随机推荐

  1. 201709-3 JSON查询

    问题描述 JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式,可以用来描述半结构化的数据.JSON 格式中的基本单元是值 (value),出于简化的目的本题 ...

  2. 【动态规划】Mathematical Curse

    [来源]:2018年焦作网络赛B [题意]: 有n个数字,有m个符号运算.通过不回头(即选取m个数有顺序可言),消除巫术的,并达到最大的价值. 其实意思就是在数组里选取一段子序列,然后进行m次加减乘除 ...

  3. Q_OBJECT提供了信号槽机制、国际化机、RTTI 的反射能力(cpp中使用Q_OBJECT导致无法处理moc,就需要#include “moc_xxx.h”)

     只有继承了QObject类的类,才具有信号槽的能力.所以,为了使用信号槽,必须继承QObject.凡是QObject类(不管是直接子类还是间接子类),都应该在第一行代码写上Q_OBJECT.不管是不 ...

  4. LeetCode面试常见100题( TOP 100 Liked Questions)

    LeetCode面试常见100题( TOP 100 Liked Questions) 置顶 2018年07月16日 11:25:22 lanyu_01 阅读数 9704更多 分类专栏: 面试编程题真题 ...

  5. GridView直接打印

    /// <summary> /// 打印功能 /// </summary> /// <param name="panel">打印控件</p ...

  6. 【原创】大数据基础之Kudu(5)kudu增加或删除目录/数据盘

    kudu加减数据盘不能直接修改配置fs_data_dirs后重启,否则会报错: Check failed: _s.ok() Bad status: Already present: FS layout ...

  7. luogu题解P2312解方程--暴力模+秦九韶

    题目链接 https://www.luogu.org/problemnew/show/P2312 分析 这道题很毒啊,这么大的数. 但是如果多项式\(\sum_{i=0}^N a[i]*X^i=0\) ...

  8. 4.图片左轮播图(swiper)

    一.html部分 二.js部分 三.源代码部分 <body> <div id="box"> <img src="imges/111.jpg& ...

  9. 使用脚本启动fabric时出错

    Error: got unexpected status: BAD_REQUEST -- error authorizing update: error validating ReadSet: rea ...

  10. SQL*Loader 的使用sqlldr和sqluldr2方法详解

    oracle数据导出工具sqluldr2可以将数据以csv.txt等格式导出,适用于大批量数据的导出,导出速度非常快.导出后可以使用oracle loader工具将数据导入.简介:Sqluldr2:专 ...