亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Count the Trees[HDU1131]

系統 1644 0

Count the Trees

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1248????Accepted Submission(s): 812

?

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
?

?

Source
UVA
?

?

Recommend
Eddy

If the N nodes are the same,there are h[N] different kinds of shapes.h[N] is the n-th Catalan Number.Now the N nodes are labled from 1 to N,so frac(N) should be multiplied.

      #include<iostream>

using namespace std;

#ifndef HUGEINT

#define HUGEINT

#include<string>

using namespace std;

class hugeint

{

  friend istream operator>> (istream&,hugeint&);

  friend ostream operator<< (ostream&,hugeint&);

  public:

    hugeint()

    {

      len=0;

      memset(num,0,sizeof(num));

    }

    hugeint(int x)

    {

    int p;

	  memset(num,0,sizeof(num));

      p=x;

      len=0;

      while (p>0)

      {

        len++;

        num[len]=p%10;

        p/=10;

      }

    }

    hugeint(string s)

    {

    int i;

      len=s.size();

      for (i=1;i<=len;i++)

        num[i]=int(s[len-i])-48;

    }

    istream& operator >> (istream& is)

    {

    int i;

      is>>s;

      len=s.size();

      for (i=1;i<=len;i++)

        num[i]=int(s[len-i])-48;

      return is;

    }

    ostream& operator << (ostream& os)

    {

    int i;

      for (i=len;i>=1;i--)

        cout<<num[i];

      return os;

    }

    void clear()

    {

    int i;

      for (i=1;i<=len;i++)

      {

        num[i+1]+=num[i]/10;

        num[i]%=10;

      }

      while ((num[len]==0)&&(len>1)) len--;

    }

    int compare(hugeint t)

    {

    int i;

      (*this).clear();

      t.clear();

      if (len>t.len)  return 1;

      if (len<t.len) return -1;

      for (i=len;i>=1;i--)

      {

        if (num[i]>t.num[i])  return 1;

        if (num[i]<t.num[i]) return -1;

      }

      return 0;

    }

    hugeint operator = (hugeint t)

    {

    int i;

      len=t.len;

      for (i=1;i<=len;i++)

        num[i]=t.num[i];

      return *this;

    }

    hugeint operator + (hugeint t)

    {

    int i;

      if (t.len>len) len=t.len;

      for (i=1;i<=t.len;i++) num[i]+=t.num[i];

      len++;

      (*this).clear();

      return *this;

    }

    hugeint operator - (hugeint t)

    {

    hugeint temp;

    int i;

      if ((*this).compare(t)<0)

      {

        temp=t;

        t=(*this);

      }

      else temp=(*this);

      for (i=1;i<=temp.len;i++)

      {

        temp.num[i+1]--;

        temp.num[i]+=(10-t.num[i]);

      }

      temp.clear();

      return temp;

    }

    hugeint operator * (hugeint t)

    {

    hugeint temp;

    int i,j;

      for (i=1;i<=(*this).len;i++)

        for (j=1;j<=t.len;j++)

          temp.num[i+j-1]+=(*this).num[i]*t.num[j];

      temp.len=(*this).len+t.len;

      temp.clear();

      return temp;

    }

    hugeint operator / (hugeint t)

    {

    hugeint c=0,d=0;

    int i,j,p;

      c.len=(*this).len; d.len=1;

      for (j=(*this).len;j>=1;j--)

      {

        d.len++;

        for (p=d.len;p>=2;p--)

          d.num[p]=d.num[p-1];

        d.num[1]=(*this).num[j];

        while (d.compare(t)>=0)

        {

          c.num[j]++;

          d=d-t;

        }

      }

      c.clear();

      d.clear();

      return c;

    }

    hugeint operator % (hugeint t)

    {

    hugeint c,d;

    int i,j,p;

      for (i=1;i<=1000;i++) c.num[i]=0;

      for (i=1;i<=1000;i++) d.num[i]=0;

      c.len=len; d.len=1;

      for (j=len;j>=1;j--)

      {

        d.len++;

        for (p=d.len;p>=2;p--)

          d.num[p]=d.num[p-1];

        d.num[1]=num[j];

        while (d.compare(t)>=0)

        {

          c.num[j]++;

          d=d-t;

        }

      }

      c.clear();

      d.clear();

      return d;

    }

  hugeint operator ++ ()

  {

    (*this)=(*this)+1;

    return *this;

  }

  hugeint operator -- ()

  {

    (*this)=(*this)-1;

    return *this;

  }

  hugeint operator += (hugeint t)

  {

    (*this)=(*this)+t;

    return *this;

  }

  hugeint operator -= (hugeint t)

  {

    (*this)=(*this)-t;

    return *this;

  }

  hugeint operator *= (hugeint t)

  {

    (*this)=(*this)*t;

    return *this;

  }

  hugeint operator /= (hugeint t)

  {

    (*this)=(*this)/t;

    return *this;

  }

  hugeint operator %= (hugeint t)

  {

    (*this)=(*this)%t;

    return *this;

  }

  bool operator == (hugeint t)

  {

  int i;

    if (len!=t.len) return false;

    for (i=1;i<=len;i++)

    if (num[i]!=t.num[i]) return false;

    return true;

  }

  bool operator >= (hugeint t)

  {

  int x;

    x=(*this).compare(t);

    if (x>=0) return true;

    return false;

  }

  bool operator <= (hugeint t)

  {

  int x;

    x=(*this).compare(t);

    if (x<=0) return true;

    return false;

  }

  bool operator > (hugeint t)

  {

  int x;

    x=(*this).compare(t);

    if (x>0) return true;

    return false;

  }

  bool operator < (hugeint t)

  {

  int x;

    x=(*this).compare(t);

    if (x<0) return true;

    return false;

  }

  ~hugeint() {}

  private:

    int num[1001];

    int len;

    string s;

};

#endif

hugeint h[125];

hugeint frac[125];

int i,N;

int main()

{

	frac[0]=1;

	h[0]=1;

	for (i=1;i<=100;i++) frac[i]=frac[i-1]*i;

	for (i=1;i<=100;i++)

	{

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

		hugeint tmp=i+1;

		h[i]=h[i]/tmp;

	}

	while (scanf("%d",&N)!=EOF)

	{

		if (N==0) return 0;

		hugeint ans=frac[N]*h[N];

		ans<<cout;

		cout<<endl;

	}

	return 0;

}


    

?

Count the Trees[HDU1131]


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美精品成人a多人在线观看 | 麻豆国产在线不卡一区二区 | 色姑娘久| 999国内精品永久免费视频 | 伊人国产在线观看 | 欧美亚洲国产成人精品 | 一本大道久久香蕉成人网 | 夭天干天天做天天免费看 | 免费小视频| 亚洲精品国产福利一区二区三区 | 男人午夜| 亚洲狠狠婷婷综合久久久久网站 | 天天曰夜夜操 | 小香蕉影院 | 在线综合+亚洲+欧美中文字幕 | 久久午夜影院 | 在线播放精品 | 亚洲婷婷在线 | 亚洲a成人7777777久久 | 中文字幕在线看视频一区二区三区 | 国产品精人成福利视频 | 久久77777| 日日摸夜夜爽夜夜爽出水 | 四虎成人免费网站在线 | 国产aⅴ精品一区二区三区久久 | 全部免费的毛片在线看青青 | 国产美女亚洲精品久久久毛片 | 精品一区二区三区的国产在线观看 | 亚欧有色亚欧乱色视频 | 日韩一区二区免费看 | 亚洲精品成人7777在线观看 | 成人欧美视频在线看免费 | 999国产高清在线精品 | 久久福利青草精品免费 | 麻豆狠色伊人亚洲综合网站 | 日本一区二区三区免费在线观看 | 九热视频 | 国产剧情一区二区三区 | 国产精品天干天干 | 毛片一区二区三区 | 欧美 日产 国产精选 |