有一種四位數abcd, 其中a>b,b<c,c>d; 例如7350,1061,9582試問此種四位數有幾個?

2015-10-18 7:56 am

回答 (1)

2015-10-18 10:20 am
✔ 最佳答案
當 b = 0
a = 1 ~ 9
當 c = 1 , d = 0 , 有 1 組解
當 c = 2 , d = 0 ~ 1 , 有 2 組解
.........
當 c = 9 , d = 0 ~ 8 , 有 9 組解
因為 c,d 的組合由 b 決定, 與 a 無關 , 所以:
可能組數
= a的可能數 * (c,d)的組合數
= 9 * ( 1 + 2 + ..... + 9 )
= 9 * 9(1+9)/2
= 9^2 * 10 / 2

當 b = 1
a = 2 ~ 9
當 c = 2 , d = 0 ~ 1 , 有 2 組解
當 c = 3 , d = 0 ~ 2 , 有 3 組解
.........
當 c = 9 , d = 0 ~ 8 , 有 9 組解
可能組數
= a的可能數 * (c,d)的組合數
= 8 * ( 2 + 3 + ..... + 9 )
= 8 * 8(2+9)/2
= 8^2 * 11 / 2

當 b = 2 ~ 7 , 與以上類似, 故省略

當 b = 8
a = 9 , c = 9 , d = 0 ~ 8
可能組數 = 9

所有可能組數
= (9^2)*10/2 + (8^2)*11/2 + ..... + (1^2)*18/2
= (1/2) * Σ (k^2)*( 19 - k ) , from k = 1 to k = 9
= (1/2) * [ 19*Σ k^2 - Σ k^3 ]
= (19/2)*Σ k^2 - (1/2)*Σ k^3
= (19/2)*n(n+1)(2n+1)/6 - (1/2)*[ n(n+1)/2 ]^2 , where n = 9
= (19/2)*9*10*19/6 - (1/2)( 9*10/2 )^2
= 2705.5 - 1012.5
= 1695

Ans: 1695 個

驗證:
可以用程式驗證, 以下為 Excel VBA 程式碼:
----------------------------------------------------------------
Sub Ex()

S = 0

For n = 1000 To 9999
T = n

d = T Mod 10
T = Int(T / 10)

c = T Mod 10
T = Int(T / 10)

b = T Mod 10
T = Int(T / 10)

a = T Mod 10

If a > b And b < c And c > d Then
S = S + 1
End If
Next

[A1] = S

End Sub
----------------------------------------------------------------
執行結果為 1695


收錄日期: 2021-05-02 14:06:48
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20151017235637AAosLCy

檢視 Wayback Machine 備份