'千万别用递归计算,慢死【以下算法1秒就能计算完毕,哪怕100阶都没问题】
f(37)= 3831006429
Private Sub Command1_Click()
Dim sum
n = Val(Text1.Text)
ReDim sum(1 To n) As Double
If n > 3 Then
sum(1) = 1
sum(2) = 2
sum(3) = 4
End If
For i = 4 To n
sum(i) = sum(i - 1) + sum(i - 2) + sum(i - 3)
Label1.Caption = sum(n)
DoEvents
Next
If n = 1 Then Label1.Caption = 1
If n = 2 Then Label1.Caption = 2
If n = 3 Then Label1.Caption = 4
End Sub
f(n) = f(n-1) + f(n-2) + f(n-3)
1
1种
2
2种
3
4种
4
7种
5
13种
6
24种
7
44种
8
81种
9
149种
10
274种
[此贴子已经被作者于2018-6-6 21:52编辑过]