• [AHOI2012] 树屋阶梯


    有无穷多的任意尺寸矩形,搭建一个 (N) 级正阶梯有多少种方案?

    Solution

    任意大小为 (i) 的阶梯,都可以由左上角放一块大小为 (j) 的,右下角放一块大小为 (i-j-1) 的来构成,每一块内部递归填充,对应 Catalan 数

    实现需要高精乘单精,高精除单精

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxlen = 1005;
    
    class gint {
    public:
        int len, s[maxlen];
        gint() { (*this) = 0; }
        gint(int inte) { (*this) = inte; }
        gint(const char *str) { (*this) = str; }
        friend ostream &operator<<(ostream &cout, const gint &x);
        gint operator=(int inte);
        gint operator=(const char *str);
        gint operator=(const gint &b);
        gint operator*(const gint &b);
        gint operator+(const gint &b);
        gint operator-(const gint &b);
        gint operator/(const gint &b);
        //gint operator%(const gint &b);
        //bool operator<(const gint &b);
        //bool operator>(const gint &b);
        int Compare(const gint &b);
    };
    
    ostream &operator<<(ostream &cout, const gint &x) {
        for (int i = x.len; i >= 1; i--) cout << x.s[i];
        return cout;
    }
    gint gint::operator=(const char *str) {
        len = (int)strlen(str);
        for (int i = 1; i <= len; i++) s[i] = str[len - i] - '0';
        return *this;
    }
    gint gint::operator=(int inte) {
        if (inte == 0) {
            len = 1;
            s[1] = 0;
            return (*this);
        }
        for (len = 0; inte > 0;) {
            s[++len] = inte % 10;
            inte /= 10;
        }
        return *this;
    }
    gint gint::operator=(const gint &b) {
        len = b.len;
        for (int i = 1; i <= len; i++) s[i] = b.s[i];
        return *this;
    }
    int gint::Compare(const gint &y) {
        if (len > y.len)
            return 1;
        if (len < y.len)
            return -1;
        int i = len;
        while ((i > 1) && (s[i] == y.s[i])) i--;
        return s[i] - y.s[i];
    }
    gint gint::operator*(const gint &b) {
        int i, j;
        gint c;
        c.len = len + b.len;
        for (i = 1; i <= c.len; i++) c.s[i] = 0;
        for (i = 1; i <= len; i++)
            for (j = 1; j <= b.len; j++) c.s[i + j - 1] += s[i] * b.s[j];
        for (i = 1; i < c.len; i++) {
            c.s[i + 1] += c.s[i] / 10;
            c.s[i] %= 10;
        }
        while (c.s[i]) {
            c.s[i + 1] = c.s[i] / 10;
            c.s[i] %= 10;
            i++;
        }
        while (i > 1 && !c.s[i]) i--;
        c.len = i;
        return c;
    }
    gint gint::operator/(const gint &b) {
        int i, j;
        gint d(0), c;
        for (i = len; i > 0; i--) {
            if (!(d.len == 1 && d.s[1] == 0)) {
                for (j = d.len; j > 0; j--) d.s[j + 1] = d.s[j];
                ++d.len;
            }
            d.s[1] = s[i];
            c.s[i] = 0;
            while ((j = d.Compare(b)) >= 0) {
                d = d - b;
                c.s[i]++;
                if (j == 0)
                    break;
            }
        }
        c.len = len;
        while ((c.len > 1) && (c.s[c.len] == 0)) c.len--;
        return c;
    }
    gint gint::operator+(const gint &b) {
        int i;
        gint c;
        c.s[1] = 0;
        for (i = 1; i <= len || i <= b.len || c.s[i]; i++) {
            if (i <= len)
                c.s[i] += s[i];
            if (i <= b.len)
                c.s[i] += b.s[i];
            c.s[i + 1] = c.s[i] / 10;
            c.s[i] %= 10;
        }
        c.len = i - 1;
        if (c.len == 0)
            c.len = 1;
        return c;
    }
    gint gint::operator-(const gint &b) {
        int i, j;
        gint c;
        for (i = 1, j = 0; i <= len; i++) {
            c.s[i] = s[i] - j;
            if (i <= b.len)
                c.s[i] -= b.s[i];
            if (c.s[i] < 0) {
                j = 1;
                c.s[i] += 10;
            } else
                j = 0;
        }
        c.len = len;
        while (c.len > 1 && !c.s[c.len]) c.len--;
        return c;
    }
    
    signed main() {
        gint a=1;
        int n;
        cin>>n;
        for(int i=2;i<=2*n;i++) a=a*gint(i);
        for(int i=1;i<=n;i++) a=a/gint(i);
        for(int i=1;i<=n+1;i++) a=a/gint(i);
        cout<<a;
    }
    
    
  • 相关阅读:
    Ionic 2.0 相关资料
    Tkinter的Menubutton组件
    Tkinter的Menubutton组件之OptionMenu
    Tkinter的Menu组件
    Tkinter的Scale组件
    Tkinter的Scrollbar组件
    Tkinter的Listbox组件
    Tkinter的Text组件
    Tkinter的Spinbox组件
    Tkinter的Label组件
  • 原文地址:https://www.cnblogs.com/mollnn/p/12596408.html
Copyright © 2020-2023  润新知