
[理工] 108交大資演 23小題


問這題,前情提要答案是 D
而原題答案 X = 91
(4 + 4) + 8 + (5 + 4) + (3 + 5)
= (8 + 8) + (9 + 8) = (16 + 17)
→ 8 + 9 + 8 + 16 + 17 +33 = 91
我是想問演算法實作的部分,
看之前上討論只說可以用 matrix chain 類似方式去求解,
而 matrix chain 最快可在 O(n lg n )下實作
該篇算法
http://i.stanford.edu/pub/cstr/reports/cs/tr/81/875/CS-TR-81-875.pdf
以下是我的想法 :
Find_Small_Intermediate_Sum(int *list, int list_size)
Sequential search list, determine the total size is odd or even
if(list_size % 2 == 0){
Divide the list into group, which group size is 2
Calculate the sum for the each group, put it into the list
Find_Small_Intermediate(list, list_size / 2)
}else{
list \ the biggest one // Don't calculate the biggest one
Divide the list into group, which group size is 2
Calculate the sum for the each group, put it into the list
Find_Small_Intermediate(list, list_size / 2)
}
# 演算法步驟
1. Split the list // O(log n)
2. 判斷總數為何 若為基數 先去除最大項, 偶數不變 // O(n)
3. 接下來依剩下儲存值與相臨數值相加之後 merge // O(n)
有問題歡迎指證 感恩
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.37.48.158 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1640364537.A.7E0.html
※ 編輯: jacksoncsie (114.37.48.158 臺灣), 12/25/2021 01:03:47
推
12/25 12:46,
4年前
, 1F
12/25 12:46, 1F
→
12/25 12:48,
4年前
, 2F
12/25 12:48, 2F
→
12/25 12:49,
4年前
, 3F
12/25 12:49, 3F
→
12/25 13:17,
4年前
, 4F
12/25 13:17, 4F
→
12/25 13:19,
4年前
, 5F
12/25 13:19, 5F
→
12/25 13:20,
4年前
, 6F
12/25 13:20, 6F
→
12/25 13:20,
4年前
, 7F
12/25 13:20, 7F
→
12/25 13:21,
4年前
, 8F
12/25 13:21, 8F
→
12/25 13:23,
4年前
, 9F
12/25 13:23, 9F

→
12/25 13:27,
4年前
, 10F
12/25 13:27, 10F
→
12/25 13:27,
4年前
, 11F
12/25 13:27, 11F

→
12/25 13:28,
4年前
, 12F
12/25 13:28, 12F
→
12/26 11:55,
4年前
, 13F
12/26 11:55, 13F
推
12/27 11:51,
3年前
, 14F
12/27 11:51, 14F
→
12/27 11:51,
3年前
, 15F
12/27 11:51, 15F
→
12/27 11:52,
3年前
, 16F
12/27 11:52, 16F
→
12/27 22:21,
3年前
, 17F
12/27 22:21, 17F
→
12/27 22:21,
3年前
, 18F
12/27 22:21, 18F