In combinatorial mathematics, the Lobb number Lm, n counts the number of ways that n + m open parentheses can be arranged to form the start of a valid sequence of balanced parentheses.
The Lobb number are parameterized by two non-negative integers m and n with n >= m >= 0. It can be obtained by:
![]()
Lobb Number is also used to count the number of ways in which n + m copies of the value +1 and n – m copies of the value -1 may be arranged into a sequence such that all of the partial sums of the sequence are non- negative.
Examples :
Input : n = 3, m = 2 Output : 5 Input : n =5, m =3 Output :35
The idea is simple, we use a function that computes binomial coefficients for given values. Using this function and above formula, we can compute Lobb numbers.
C++
// CPP Program to find Ln, m Lobb Number. #include <bits/stdc++.h> #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 = 5m = 3print(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
<?php // PHP Program to find Ln, // m Lobb Number. $MAXN =109; // Returns value of Binomial // Coefficient C(n, k) function binomialCoeff($n, $k) { $C= array(array()); // Calculate value of Binomial // Coefficient in bottom up manner for ($i = 0; $i <= $n; $i++) { for ($j = 0; $j <= min($i, $k); $j++) { // Base Cases if ($j == 0 || $j == $i) $C[$i][$j] = 1; // Calculate value using p // reviously 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. function lobb($n, int $m) { return ((2 * $m + 1) * binomialCoeff(2 * $n, $m + $n)) / ($m + $n + 1); } // Driven Code $n = 5;$m = 3; echo lobb($n, $m); // This code is contributed by anuj_67. ?> |
Output :
35
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Minimum number of squares whose sum equals to given number n
- Finding number of digits in n'th Fibonacci number
- Super Ugly Number (Number whose prime factors are in given set)
- Get the kth smallest number using the digits of the given number
- Number of compositions of a natural number
- Number of digits in the nth number made of given four digits
- Count number of triplets with product equal to given number with duplicates allowed | Set-2
- Number of ways to represent a number as sum of k fibonacci numbers
- Count number of triplets with product equal to given number with duplicates allowed
- Check if the given number is Ore number or not
- Check if a number is an Achilles number or not
- Given number of matches played, find number of teams in tournament
- Find the maximum number of composite summands of a number
- Minimum number of cubes whose sum equals to given number N
- Number of ways to get a given sum with n number of m-faced dices
- Check if a number is Flavius Number
- Calculate the number of set bits for every number from 0 to N
- Minimum number of squares whose sum equals to given number N | set 2
- Number of substrings with length divisible by the number of 1's in it
- Maximum number of prime factors a number can have with exactly x factors
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

