Game of Connections

Game of Connections

这个题也是直接求卡特兰数,不过数据有一点大,不能够直接求,因为杭电不能交 python 不然我就用 python 写了....
对于这么大的数据,还不能写 python 就只能用高精度

代码:

// Created by CAD on 2019/8/15.
#include <bits/stdc++.h>
#define mst(name, value) memset(name,value,sizeof(name))
using namespace std;
using ll=long long;
struct BigInt {
    const static int mod=1e4;
    const static int blo=4;
    int a[600], len;
    BigInt() { mst(a, 0), len=1; }
    BigInt(int v)                              //用int初始化
    {
        mst(a, 0);
        len=0;
        do
        {
            a[len++]=v%mod;
            v/=mod;
        } while (v);
    }
    BigInt operator+(const BigInt &b) const     //重载加法运算符
    {
        BigInt res;
        res.len=max(len, b.len);
        for (int i=0; i<=res.len; ++i)
            res.a[i]=0;
        for (int i=0; i<res.len; ++i)
            res.a[i]+=((i<len) ? a[i] : 0)+((i<b.len) ? b.a[i] : 0),
            res.a[i+1]+=res.a[i]/mod, res.a[i]%=mod;
        if (res.a[res.len]>0) res.len++;
        return res;
    }
    BigInt operator*(const BigInt &b) const      //重载乘法运算符
    {
        BigInt res;
        for (int i=0; i<len; ++i)
        {
            int up=0;
            for (int j=0; j<b.len; ++j)
            {
                int temp=a[i]*b.a[j]+res.a[i+j]+up;
                res.a[i+j]=temp%mod, up=temp/mod;
            }
            if (up!=0) res.a[i+b.len]=up;
        }
        res.len=len+b.len;
        while (res.a[res.len-1]==0 && res.len>1) res.len--;
        return res;
    }
    void output()                                  //输出
    {
        printf("%d", a[len-1]);
        for (int i=len-2; i>=0; --i)
            printf("%04d", a[i]);
        puts("");
    }
};
BigInt f[105];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    f[0]=f[1]=BigInt(1);
    for (int i=2; i<=100; ++i)
    {
        for (int j=0; j<=i-1; ++j)
            f[i]=f[i]+f[j]*f[i-j-1];
    }
    int n;
    while (cin >> n && n!=-1)
        f[n].output();
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
大方的大熊猫准备进厂:1.教育背景:你希望从事什么专业的工作你的主修课就是什么;成绩优秀是你应该做的,没什么可描述的,成绩不优秀也许人家在大学忙着创业呢?(成绩优秀不一定是好事,只能说明多元化的大学你上成了高中,没有真正上明白大学,反而体现了你死板,不爱社交,没有别的突出能力) 2.实践经历:你想表达的意思没有说清楚。你是说你会个性化服务,还是你有实习经历。如果没有带来,经济收益,表彰,更好的发展前景,那你还不如说说提升了自己哪些技能。你说有人给你送锦旗我都能明白你优秀,但是你说你会xxxx,你说这话谁信,证据呢。 3.入伍经历:你描述的就是你的工作职责或者你应该做的,并没有体现出来你把这个事情做好了,而且入伍经历并不能证明你能干好你要应聘的工作,不如只写经历其余所有内容都不写。 4.荣誉技能:重点突出一下,但不要过多描述,这些荣誉的含金量懂得都懂。 重点:你要应聘什么工作(具体岗位,实习生不具体),你的期望薪资
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务