Expressions
Time limit1sMemory limit128 MB
Count balanced parenthesis strings of a given total length that have exactly a given maximum nesting depth.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Let be the smallest set defined by the following rules:
- the empty string belongs to ;
- if and belong to , then both and belong to .
The elements of are called correctly built parenthesis expressions. For example, these strings are correctly built parenthesis expressions:
()(())()
(()(()))
while these are not:
(()))(()
())(()
Let be a correctly built parenthesis expression. The length of is the number of single parentheses in . The depth of is defined by:
Given two positive integers and , determine how many correctly built parenthesis expressions have length exactly and depth exactly .
Input
A single line containing two integers and separated by one space, with and .
Output
Print a single integer: the number of correctly built parenthesis expressions of length and depth .
Hint
There are exactly three correctly built parenthesis expressions of length and depth :
(())()
()(())
(()())