2025年8月17日 星期日

322. Coin Change

 動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

2025年8月15日 星期五

91. Decode Ways

 動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

2025年8月14日 星期四

5. Longest Palindromic Substring

 動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

2025年8月13日 星期三

213. House Robber II

  動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

198. House Robber

 動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

2025年8月12日 星期二

70. Climbing Stairs

動規五部曲分別為:

1. 確定dp數組(dp table)以及下標的含義

2. 確定遞推公式

3. dp數組如何初始化

4. 確定遍歷順序

5. 舉例推導dp數組

(from 代碼隨想錄)

2025年2月3日 星期一

使用 accelerate 將部分參數 offload 到 CPU 上

 有時手上的 GPU memory 不夠跑模型,舉例:eva-clip-8b,可以使用 accelerate 將部分參數 offload 到 CPU 上。

https://github.com/baaivision/EVA/issues/147

https://blog.csdn.net/qq_42363032/article/details/139597486

2025年1月29日 星期三

刪除本地端下載的 huggingface 模型

 https://stackoverflow.com/questions/65037368/remove-downloaded-tensorflow-and-pytorchhugging-face-models


pip install huggingface_hub["cli"]

huggingface-cli delete-cache

2025年1月13日 星期一

Windows 壓縮 vhdx

 https://answers.microsoft.com/en-us/windows/forum/all/optimize-vhd-not-found-in-windows-10-home/a727b760-0f82-4d0f-8480-d49eeaeb11a2


照做即可。

2024年2月17日 星期六

1642. Furthest Building You Can Reach

解題思路

我們可以用的有 ladder (無視兩鄉鄰建築物落差) 跟 brick。很直覺的是,我們肯定是把落差最大的那幾次用 ladder,其他幾次用 brick。

所以可以得知下面的公式:

落差總和 - 最大幾次總和 = 剩下來用 brick 補足的 <= 既有 brick 數


求最大幾次(用 ladder 的),可以用 minHeap 來完成,概念可參考 215. Kth Largest Element in an Array 這題。

程式碼
class Solution {
public:
    int furthestBuilding(vector<int>& heights, int bricks, int ladders) {
        long long int sum = 0, topKSum = 0, i;
        priority_queue<int, vector<int>, greater<int>> pq;

        for(i=1; i<heights.size(); i++)
        {
            int diff = heights[i] - heights[i-1];
            if(diff > 0)
            {
                sum += diff;
                topKSum += diff;
                pq.push(diff);
                if(pq.size() > ladders)
                {
                    topKSum -= pq.top();
                    pq.pop();
                }
                if(sum - topKSum > bricks)
                    break;
            }
        }
        return i-1;
    }
};