zoukankan      html  css  js  c++  java
  • csu 10月 月赛 B 题 Scoop water

    一个卡特兰数的应用;

    卡特兰数主要有以下几个用途:

    1.不同的出栈入栈数;

    2.n个点组成的不同的二叉树的数目;

    3.凸多边形的三角剖分划分;

    4.括号化问题;

    通项公式是:h(n) = C(2n-2,n-1)/n,n=1,2,3,...

    递推公式:h(n) = h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1),n>=2

    这个题就是第一种情况。

    代码:

     1 #include<cstdio>
     2 #define maxn 10009
     3 #define mod 1000000007
     4 #define ll long long
     5 using namespace std;
     6 
     7 ll f[maxn];
     8 
     9 ll katelant(int n)
    10 {
    11     if(n==2)return 1;
    12     if(n==3)return 1;
    13     for(int i=2; i<n; i++)
    14     {
    15         if(f[i]==0)f[i]=katelant(i)%mod;
    16         if(f[n-i+1]==0)f[n-i+1]=katelant(n-i+1)%mod;
    17         f[n]+=(f[i]*f[n-i+1])%mod;
    18     }
    19     return f[n];
    20 }
    21 
    22 int main()
    23 {
    24     f[2]=f[3]=1;
    25     katelant(10005);
    26     int n;
    27     while(scanf("%d",&n)!=EOF)
    28     {
    29         printf("%lld
    ",f[n+2]);
    30     }
    31     return 0;
    32 }
    View Code
  • 相关阅读:
    Gitlab使用腾讯企业邮箱
    查看Binlog内容
    微信小游戏手记
    clickhouse手记
    腾讯云手记
    go框架gin
    go idea debug
    go手记
    crontab手记
    Laravel-cors 跨域
  • 原文地址:https://www.cnblogs.com/yours1103/p/3349599.html
Copyright © 2011-2022 走看看