lua计算CnM
c = {}
function cf(n,m)
if(n == m) then
c[n][m] = 1
elseif(n < m) then
c[n][m] = 0
elseif(m == 0) then
c[n][m] = 1
else
if(c[n-1] == nil) then
c[n-1] = {}
end
if(c[n-1][m-1] == nil) then
c[n-1][m-1] = cf(n-1, m-1)
end
if(c[n-1][m] == nil) then
c[n-1][m] = cf(n-1, m)
end
if(c[n] == nil) then
c[n] = {}
end
c[n][m] = c[n-1][ m-1] + c[n-1][m]
end
return c[n][m]
end
print(cf(10,3))
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。