演算法作業10
第1題: 01背包問題
已知有六個物品,其價值和重量如下,背包重量限制為34。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 仿照課本以tree search來解。
- 請將下圖中的框框中,填入其upper bound與lower bound
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
已經按照大小排了
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
只需要從前面開始取就好
0
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
lower bound
upper bound
1
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
lower bound
upper bound
2
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
lower bound
upper bound
3
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
lower bound
upper bound
4
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
|
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
10 |
4 |
4 |
4 |
2 |
|
10 |
19 |
8 |
10 |
12 |
8 |
|
7/10 |
10/19 |
1/2 |
2/5 |
1/3 |
1/4 |
lower bound
upper bound
結果
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
第2題: A* 解multi-stage shortest path problem
- 請使用A* 找出S到T的最短路徑。請畫出樹狀圖,並標示各點的cost,並註明哪裏分枝不用再繼續尋找了
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
過程
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
結果
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
第3題: Channel Routing Problem
- 請使用A* 解Channel Routing Problem。
- 本題將原本題目的net 7移除,只剩下7個nets,請找出最少track的安排方式。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
更新後的水平&垂直限制
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
過程
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
結果
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
第4題: 合併二元樹
解題思路
DFS跑一次,主要是NULL的處理比較麻煩
其他都還好
程式碼
測試輸出輸入的畫面截圖

花費時間
10分鐘
完成程度
完全自己解出
第5題: 最深葉子的最低共同祖先
解題思路
我用後序的想法去寫,然後我寫一個函數專門計算深度&答案
然後因為後序,所以越上面的點會越晚被更新,
最後被更新的就會是答案,yeah
程式碼
測試輸出輸入的畫面截圖

花費時間
30(想錯的時間) + 15分鐘
完成程度
完全自己解出
第6題:
解題思路
寫個遞迴,判斷是否下面的子樹都是0或空,如果是就把點改成NULL
並回傳0
反之就回傳1,以便上面的點去保留
這串就是在回傳左右子樹的檢查結果跟自身的檢查結果這樣
程式碼
測試輸出輸入的畫面截圖

花費時間
15分鐘
完成程度
完全自己解出
心得:
已填