设 f i , a , b , c f_{i,a,b,c} fi,a,b,c表示当前深度小于等于 i i i并且有 a a a对 { } \{~\} { }, b b b对 [ ] [~] [ ], c c c对 ( ) (~) ( )的方案数,根据优先级,将 f i , a , b , c f_{i,a,b,c} fi,a,b,c分成左串,以及右串,现在假设是左串往外套一层括号( { } \{~\} { }或 [ ] [~] [ ]或 ( ) (~) ( )),其中左、右串可能为空,有
f i , a , b , c = { 1 i f ( a + b + c = = 0 ) ∑ p = 1 c f i − 1 , 0 , 0 , p − 1 ∗ f i , a , b , c − p + ∑ q = 1 b ∑ p = 0 c f i − 1 , 0 , q − 1 , p ∗ f i , a , b − q , c − p + ∑ w = 1 a ∑ q = 0 b ∑ p = 0 c f i − 1 , w − 1 , p , q ∗ f i , a − w , b − p , c − q e l s e f_{i,a,b,c}=\begin{cases}1 ~~if(a+b+c==0)\\\sum\limits_{p=1}^cf_{i-1,0,0,p-1}*f_{i,a,b,c-p}+\sum\limits_{q=1}^b\sum\limits_{p=0}^c f_{i-1,0,q-1,p}*f_{i,a,b-q,c-p}+\sum\limits_{w=1}^{a}\sum\limits_{q=0}^b \sum\limits_{p=0}^c f_{i-1,w-1,p,q}*f_{i,a-w,b-p,c-q}~~else \end{cases} fi,a,b,c=⎩⎪⎨⎪⎧1 if(a+b+c==0)p=1∑cfi−1,0,0,p−1∗fi,a,b,c−p+q=1∑bp=0∑cfi−1,0,q−1,p∗fi,a,b−q,c−p+w=1∑aq=0∑bp=0∑cfi−1,w−1,p,q∗fi,a−w,b−p,c−q else