小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

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

题目:

整数数列 {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

posted on 2005-12-12 21:07  王峰炬  阅读(452)  评论(0)    收藏  举报

导航