📌  相关文章
📜  阁楼号

📅  最后修改于: 2021-04-24 22:08:55             🧑  作者: Mango

在组合数学中,洛伯数L m,n表示可以排列n + m个开放括号的方式,以形成有效的平衡括号序列的开头。
Lobb数由两个非负整数m和n进行参数化,其中n> = m> =0。可以通过以下方式获得:
L_{m,n} = \frac{2\times m + 1}{m + n + 1}\binom{2\times n}{m + n}
Lobb Number还用于计算将值+1的n + m个副本和值-1的n – m个副本排列为一个序列的方式的数量,以使该序列的所有部分和都不为- 消极的。
例子 :

Input : n = 3, m = 2
Output : 5

Input : n =5, m =3
Output :35

这个想法很简单,我们使用一个函数来计算给定值的二项式系数。使用此函数和上面的公式,我们可以计算罗布数。

C++
// CPP Program to find Ln, m Lobb Number.
#include 
#define MAXN 109
using namespace std;
 
// Returns value of Binomial Coefficient C(n, k)
int binomialCoeff(int n, int k)
{
    int C[n + 1][k + 1];
 
    // Calculate value of Binomial Coefficient in
    // bottom up manner
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= min(i, k); j++) {
            // Base Cases
            if (j == 0 || j == i)
                C[i][j] = 1;
 
            // Calculate value using previously stored values
            else
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
 
    return C[n][k];
}
 
// Return the Lm, n Lobb Number.
int lobb(int n, int m)
{
    return ((2 * m + 1) * binomialCoeff(2 * n, m + n)) / (m + n + 1);
}
 
// Driven Program
int main()
{
    int n = 5, m = 3;
    cout << lobb(n, m) << endl;
    return 0;
}


Java
// JAVA Code For Lobb Number
import java.util.*;
 
class GFG {
     
    // Returns value of Binomial
    // Coefficient C(n, k)
    static int binomialCoeff(int n, int k)
    {
        int C[][] = new int[n + 1][k + 1];
      
        // Calculate value of Binomial
        // Coefficient in bottom up manner
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= Math.min(i, k);
                                        j++) {
                // Base Cases
                if (j == 0 || j == i)
                    C[i][j] = 1;
      
                // Calculate value using
                // previously stored values
                else
                    C[i][j] = C[i - 1][j - 1] +
                              C[i - 1][j];
            }
        }
      
        return C[n][k];
    }
     
    // Return the Lm, n Lobb Number.
    static int lobb(int n, int m)
    {
        return ((2 * m + 1) * binomialCoeff(2 * n, m + n)) /
                                             (m + n + 1);
    }
     
    /* Driver program to test above function */
    public static void main(String[] args)
    {
        int n = 5, m = 3;
        System.out.println(lobb(n, m));
         
    }
}
 
// This code is contributed by Arnav Kr. Mandal.


Python 3
# Python 3 Program to find Ln,
# m Lobb Number.
 
# Returns value of Binomial
# Coefficient C(n, k)
def binomialCoeff(n, k):
 
    C = [[0 for j in range(k + 1)]
             for i in range(n + 1)]
 
 
    # Calculate value of Binomial
    # Coefficient in bottom up manner
    for i in range(0, n + 1):
        for j in range(0, min(i, k) + 1):
            # Base Cases
            if (j == 0 or j == i):
                C[i][j] = 1
 
            # Calculate value using
            # previously stored values
            else:
                C[i][j] = (C[i - 1][j - 1]
                            + C[i - 1][j])
         
    return C[n][k]
 
# Return the Lm, n Lobb Number.
def lobb(n, m):
 
    return (((2 * m + 1) *
        binomialCoeff(2 * n, m + n))
                      / (m + n + 1))
 
# Driven Program
n = 5
m = 3
print(int(lobb(n, m)))
 
# This code is contributed by
# Smitha Dinesh Semwal


C#
// C# Code For Lobb Number
using System;
 
class GFG {
 
    // Returns value of Binomial
    // Coefficient C(n, k)
    static int binomialCoeff(int n, int k)
    {
         
        int[, ] C = new int[n + 1, k + 1];
 
        // Calculate value of Binomial
        // Coefficient in bottom up manner
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= Math.Min(i, k);
                j++) {
                     
                // Base Cases
                if (j == 0 || j == i)
                    C[i, j] = 1;
 
                // Calculate value using
                // previously stored values
                else
                    C[i, j] = C[i - 1, j - 1]
                                + C[i - 1, j];
            }
        }
 
        return C[n, k];
    }
 
    // Return the Lm, n Lobb Number.
    static int lobb(int n, int m)
    {
        return ((2 * m + 1) * binomialCoeff(
                 2 * n, m + n)) / (m + n + 1);
    }
 
    /* Driver program to test above function */
    public static void Main()
    {
        int n = 5, m = 3;
         
        Console.WriteLine(lobb(n, m));
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出 :

35