关于不定方程整数解的个数的求法

题目:

整数数列 {xn} ∈[0,max] , 且 ∑xi=sum, 则这样的序列共有多少个?

方法:递归

Function resultcount(ByVal n As Integer, ByVal max As Integer, ByVal sum As Integer) As Integer
If n * max < sum Then resultcount = 0: Exit Function
If n = 1 Then resultcount = 1
If sum = 1 Then resultcount = n
If n > 1 Then
Dim i As Integer, temp As Integer
temp = 0
For i = 0 To max
temp = temp + resultcount(n - 1, max, sum - i)
Next
resultcount = temp
End If
End Function

你可能感兴趣的:(关于不定方程整数解的个数的求法)