hdu1134、1130-Catalan數

來源:互聯網
上載者:User

新年的第一篇博文

給自己加油 !!告別寒假的安逸 為夢想邁出一小步、、、、

http://acm.hdu.edu.cn/showproblem.php?pid=1134

題意:2N個人依序站成一圈,兩兩組成一隊,不能交叉,組合的組數

http://acm.hdu.edu.cn/showproblem.php?pid=1130

題意:給定N個節點,能構成多少種不同的二叉樹。

代碼一樣,如下:

#include<iostream>using namespace std;int num[101][101]={0};//強烈懷疑:101錯誤的寫成100.////////////////////////答案就是錯誤的。Why?void Catalan(){    int i,j;    num[0][0]=1;    num[1][0]=1;    int len=1;    int flag;    for(i=2;i<101;i++)    {        //乘4n-2        int k=4*i-2;        flag=0;        for(j=0;j<=len;j++)        {            int z=flag+num[i-1][j]*k;            num[i][j]=z%10;            flag=z/10;        }        while(flag)        {            num[i][j++]=flag%10;            flag/=10;        }        len=j;flag=0;        //除n+1        while(j>=0)        {            int w=num[i][j]+flag*10;            num[i][j]=w/(i+1);            flag=w%(i+1);            j--;        }    }}int main(){    Catalan();    int n,i;    while(cin>>n&&n>0)    {        i=99;        while(num[n][i]==0)        {i--;}        while(i>=0)        {            cout<<num[n][i];            i--;        }        cout<<endl;    }    return 0;}

此處Catalan數的詳細資料,講解非常詳細。留個連結,隨時解疑答惑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.