出个题来个数学高手帮我算算
发布网友
发布时间:2023-01-02 16:12
我来回答
共1个回答
热心网友
时间:2023-10-09 19:00
20个数字加起来的总和为810的有几种组合 ?
你的代码做了优化:
Sub test() 'by treenewbee Reform by kagawa Dim h&, i&, j&, k&, m&, n&, cnt m = 80: n = 80: h = 810 If n * (n + 1) > h * 2 Then n = Int((Sqr(1 + 8 * h) - 1) / 2) ReDim a(n) ReDim x(m, h) For i = 1 To n a(i) = x Next For i = 1 To m If i <= n Then a(i)(i, i * (i + 1) / 2) = 1 For j = 1 To h If j <= i Then a(1)(i, j) = 1 If i > 1 Then For k = 2 To n If j > i Then a(k)(i, j) = a(k)(i - 1, j) + a(k - 1)(i - 1, j - i) Else a(k)(i, j) = a(k)(i - 1, j) End If Next End If Next Next Debug.Print For i = 1 To n If a(i)(m, h) Then cnt = cnt + a(i)(m, h): Debug.Print "n= "; i; Tab; Format(a(i)(m, h), "#,##0"); Tab; " 个组合" Next Debug.Print "m = 1 - " & m & " 组合求和 h = " & h & "
共找到 " & Format(cnt, "#,##0") & " 个解。"
End Sub复制代码输出结果如下:
n= 11 169 个组合
n= 12 4,160,649 个组合
n= 13 1,006,982,926 个组合
n= 14 57,355,250,073 个组合
n= 15 1,423,462,888,772 个组合
n= 16 19,739,540,509,130 个组合
n= 17 174,322,404,172,025 个组合
n= 18 1,060,814,803,909,130 个组合
n= 19 4,683,554,319,882,870 个组合
n= 20 15,542,763,534,960,600 个组合
n= 21 39,750,909,014,245,300 个组合
n= 22 79,755,358,529,487,100 个组合
n= 23 127,115,698,759,287,000 个组合
n= 24 162,295,338,438,427,000 个组合
n= 25 166,815,160,674,320,000 个组合
n= 26 138,302,125,967,051,000 个组合
n= 27 92,402,805,984,147,200 个组合
n= 28 49,561,661,867,959,100 个组合
n= 29 21,192,885,937,297,400 个组合
n= 30 7,148,639,681,428,040 个组合
n= 31 1,873,788,437,195,230 个组合
n= 32 373,807,123,491,784 个组合
n= 33 55,146,716,337,167 个组合
n= 34 5,778,410,524,336 个组合
n= 35 405,580,830,133 个组合
n= 36 17,431,671,949 个组合
n= 37 394,750,488 个组合
n= 38 3,513,984 个组合
n= 39 5,604 个组合
m = 1 - 80 组合求和 h = 810
共找到 908,132,205,384,686,000 个解。