<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Algorithm - Category - Wandering World</title>
        <link>http://chinyu1229.github.io/categories/algorithm/</link>
        <description>Algorithm - Category - Wandering World</description>
        <generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>chinyu0916@gmail.com (Chinyu)</managingEditor>
            <webMaster>chinyu0916@gmail.com (Chinyu)</webMaster><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Fri, 10 Sep 2021 19:00:12 &#43;0800</lastBuildDate><atom:link href="http://chinyu1229.github.io/categories/algorithm/" rel="self" type="application/rss+xml" /><item>
    <title>Link List in C</title>
    <link>http://chinyu1229.github.io/2021-09-10-linklist/</link>
    <pubDate>Fri, 10 Sep 2021 19:00:12 &#43;0800</pubDate>
    <author>Author</author>
    <guid>http://chinyu1229.github.io/2021-09-10-linklist/</guid>
    <description><![CDATA[Link List 基本概念  相同結構的東西（用struct)使用指標（pointer)串起來，相同結構的東西稱作NODE 在加入/刪除比array上好操作 有需要的時候才動態的配置空間(malloc / new) 查詢時比array慢  圖示：
靜態配置：
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  #include&lt;stdio.h&gt;#include&lt;stdlib.h&gt; struct node{ int data; struct node *next; }; typedef struct node Node; int main() { Node x, y, z; Node *ptr = &amp;x; x.data = 10; x.]]></description>
</item><item>
    <title>整數二分法 Binary Search</title>
    <link>http://chinyu1229.github.io/2021-9-7-%E4%BA%8C%E5%88%86%E6%B3%95/</link>
    <pubDate>Tue, 07 Sep 2021 23:11:12 &#43;0800</pubDate>
    <author>Author</author>
    <guid>http://chinyu1229.github.io/2021-9-7-%E4%BA%8C%E5%88%86%E6%B3%95/</guid>
    <description><![CDATA[整數二分 何時使用 有單調性（monotone)的一組數字可以二分，但沒有單調性也可以使用二分法
在何時適用 若可以找到某種性質，在右半邊滿足，左半邊不滿足(在右半邊不滿足，左半邊滿足)，就可以尋找邊界
模板code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  bool check(int x){/*stasify some conditions*/} // [l, r] -&gt; [l, mid] + [mid + 1, r] int bsearch1(int l, int r) { int mid = l + r &gt;&gt; 1; if(check(mid)) r = mid; else l = mid + 1; } // [l, r] -&gt; [l, mid - 1] + [mid, r] int bsearch2(int l, int r) { int mid = l + r + 1 &gt;&gt; 1; if(check(mid)) l = mid; else r = mid - 1; } return l; //also can return r   圖例與解釋 找尋紅色的邊界：check(mid) ：滿足紅色條件]]></description>
</item><item>
    <title>KMP算法 -- next解釋</title>
    <link>http://chinyu1229.github.io/2021-07-13-kmp%E7%AE%97%E6%B3%95/</link>
    <pubDate>Tue, 13 Jul 2021 17:40:12 &#43;0800</pubDate>
    <author>Author</author>
    <guid>http://chinyu1229.github.io/2021-07-13-kmp%E7%AE%97%E6%B3%95/</guid>
    <description><![CDATA[KMP 基本概念 一種用來字符串匹配的算法 一些定義：
 s[] 為主字串 ， p[] 是匹配串 ， 即可以理解成p是否是s的子字串 前綴：包含首位字符但不包含末位字符的子字串; 後綴：包含末位字符但不包含首位字符的子字串 部分匹配值 ： 前綴與後綴最長共有長度 next[] 存的是每個下標對應的部分匹配值   核心思考：每次匹配失敗時，把p串往後移動至next對應的值  next的含義與模擬 字串從1開始存，next[i], 是p[1,i]中前綴和後綴相同的最大長度（部分匹配值）， 定義 next[1] = 0 例如：
1 2 3  idx 1 2 3 4 5 6 str a b c a b a next 0 0 0 1 2 1   求next陣列的code
1 2 3 4 5 6 7  // m 為 p 的長度 for(int i = 2, j = 0; i &lt;= m; i++) { while(j &amp;&amp; p[i] !]]></description>
</item><item>
    <title>Backpack_Problem</title>
    <link>http://chinyu1229.github.io/2021-06-11-backpack-problem/</link>
    <pubDate>Thu, 10 Jun 2021 00:48:12 &#43;0800</pubDate>
    <author>Author</author>
    <guid>http://chinyu1229.github.io/2021-06-11-backpack-problem/</guid>
    <description><![CDATA[Backpack 0 - 1 Problem  主問題：從n個物品選一些物品，在不超過最大容量下，使得價值最大。 解空間：{x1,x2&hellip;.,xn}  xi : 0 or 1 (表示取或不取) 共有 $2^n$ 可能的解   限制條件： $\sum_{i=1}^n$ $w_ix_i$ &lt;= W 採用回溯法 限界條件：  對於任何一個中間節點z，從root到z的分支所代表的狀態已經確定，從z到子孫的節點還未確定。如果z在第t層，說明第1種物品到t-1種物品（是否裝入背包）確定，t可以沿著分支擴展確認狀態，t+1到n不確定。 目前裝入背包的物品總價用cp表示，因為還不確定t+1到n物品的狀態，先假設全部都放入背包，也就是剩餘的總價值，用rp表示。 cp + rp是所有從root出發經過中間節點z的可行解的價值上界。如果價值上界小於或等於目前的最優值，則說明節點z沒有繼續搜尋的必要 即 cp + rp &gt; bestp    solution 假設有4個物品，每個物品w [2,5,4,2], 價值v [6,3,5,4], W = 10
 初始化：sumw , sumv 統計所有物品的總重和總價 -&gt; sumw = 13, sumw = 18,目前放入背包的物品重量cw = 0, 總價cp = 0, 最優值 bestp = 0 第一層：t = 1,   判斷cw + w[1] = 2 &lt; W （滿足限制條件）向左擴展分支，令x[1] = 1, cw = cw + w[1] = 2, cp = cp+v[1] = 6，生成2好節點]]></description>
</item></channel>
</rss>
