以下程式會算出 C(N, M),即從 N 個物品中選出 M 個物品的方法數量。如果 count 的值原先為 0
,請問計算 C(5, 3) 後,count 的值為何?
unsigned int count = 0;
unsigned int getC(unsigned int N, unsigned int M){
count++;
if (N == 0) return (N == M ? 1 : 0);
else if (M == 0) return 1;
else return getC(N-1, M) + getC(N-1, M-1);
}
(A) 5
(B) 15
(C) 51
(D) 63