[103關務3等][資訊處理]資料結構第一題 - 考試
By Aaliyah
at 2015-04-29T07:32
at 2015-04-29T07:32
Table of Contents
題目是這樣(雖然大家可能都看過了,不過我還是大略抄一遍...)
兩項是係數的組合遞迴演算法如下
C(r,n) =
0, 若 r > n
1, 若 n==r
1, 若 r==0
C(n-1,r)+C(n-1,r-1), 其他
1. 寫出遞迴函數程式
2. 畫出輸入為 n=5, r=3時,遞迴呼叫的二元樹
3. 承2. 求最後回傳值
4. 承2. 共呼叫遞迴幾次
1.
我是用C++寫的
int func(int r, int n)
{
if(r > n)
return 0;
if(n==r)
return 1;
if(r==0)
return 1;
return (func((n - 1), r) + func((n - 1), (r - 1)));
}
2.
(3, 5)
/ \
(4, 3) (4, 2)
===> (4, 3) ===> 4 > 3 ===> 回傳0
===> (4, 2) ===> 4 > 2 ===> 回傳0
3. 0+0 = 0
4.我其實不太確定這叫一次還是兩次,所以我寫2
這樣也有錯嗎?感覺答案太簡單了?
祝各位金榜題名
--
兩項是係數的組合遞迴演算法如下
C(r,n) =
0, 若 r > n
1, 若 n==r
1, 若 r==0
C(n-1,r)+C(n-1,r-1), 其他
1. 寫出遞迴函數程式
2. 畫出輸入為 n=5, r=3時,遞迴呼叫的二元樹
3. 承2. 求最後回傳值
4. 承2. 共呼叫遞迴幾次
1.
我是用C++寫的
int func(int r, int n)
{
if(r > n)
return 0;
if(n==r)
return 1;
if(r==0)
return 1;
return (func((n - 1), r) + func((n - 1), (r - 1)));
}
2.
(3, 5)
/ \
(4, 3) (4, 2)
===> (4, 3) ===> 4 > 3 ===> 回傳0
===> (4, 2) ===> 4 > 2 ===> 回傳0
3. 0+0 = 0
4.我其實不太確定這叫一次還是兩次,所以我寫2
這樣也有錯嗎?感覺答案太簡單了?
祝各位金榜題名
--
Tags:
考試
All Comments
By James
at 2015-05-01T20:33
at 2015-05-01T20:33
By Lily
at 2015-05-02T07:03
at 2015-05-02T07:03
By Andrew
at 2015-05-06T18:19
at 2015-05-06T18:19
By Dora
at 2015-05-07T03:41
at 2015-05-07T03:41
By Rosalind
at 2015-05-08T16:55
at 2015-05-08T16:55
By Belly
at 2015-05-10T14:20
at 2015-05-10T14:20
By Margaret
at 2015-05-13T07:40
at 2015-05-13T07:40
By Freda
at 2015-05-18T05:50
at 2015-05-18T05:50
By Quanna
at 2015-05-20T04:09
at 2015-05-20T04:09
By Bethany
at 2015-05-23T00:21
at 2015-05-23T00:21
By Tristan Cohan
at 2015-05-26T18:03
at 2015-05-26T18:03
By William
at 2015-05-27T19:48
at 2015-05-27T19:48
By Agatha
at 2015-05-31T11:37
at 2015-05-31T11:37
By Sarah
at 2015-06-04T11:04
at 2015-06-04T11:04
By Una
at 2015-06-04T22:02
at 2015-06-04T22:02
Related Posts
會計初學問題請教
By Oscar
at 2015-04-29T00:33
at 2015-04-29T00:33
臺中補習班選擇
By Emily
at 2015-04-29T00:28
at 2015-04-29T00:28
記帳士考試中的會計學概要
By Callum
at 2015-04-28T23:46
at 2015-04-28T23:46
一套高點圖解法典?
By Necoo
at 2015-04-28T23:43
at 2015-04-28T23:43
求解吳俊 企業管理 101年 DVD書本資料
By Hazel
at 2015-04-28T21:55
at 2015-04-28T21:55