gpt4 book ai didi

algorithm - 正确排列括号的方法数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:40:11 26 4
gpt4 key购买 nike

我一直在思考这个问题:

What's the number of ways of correctly* arranging 2*n parenthesis.
*A correctly arranged sequence of parenthesis has an equal number of open and closed parenthesis at its end and a larger or equal amount of open parenthesis than the closed ones throughout the sequence.

例如,对于n=3,有5种方式:((())), ()(()), ()( )(), (())(), (()()).

我一直在考虑将嵌套括号表示为树,但没有取得太大进展。

最佳答案

你的例子相当于Dyck words的数量,可以用组合学计算,等于 Catalan number :

enter image description here

关于algorithm - 正确排列括号的方法数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34404031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com