在组合数学中,施罗德数用来描述从(0,0)到(n,n)的格路中,只能使用(1,0)、(0,1)、(1,1)三种移动方式,始终位于对角线下方且不越过对角线的路径数
DECLARE @n INT =10
DECLARE @i INT
DECLARE @rst INT
DECLARE @old INT=1CREATE TABLE #rst
(i INT ,rst int
)INSERT INTO #rst values(1,1)SET @i=2
WHILE @i<=@n
BEGIN SET @rst=0SELECT @rst=@rst+a.rst*b.rst FROM #rst a INNER JOIN (SELECT *,ROW_NUMBER() OVER(ORDER BY i desc) j FROM #rst) b ON a.i = b.jSET @rst=@rst+@oldINSERT INTO #rst values(@i,@rst)SET @i=@i+1SET @old=@rst
END SELECT * FROM #rstDROP TABLE #rst