原创 poj_2250 Compromise(輸出最長公共子序列)

【題目】 點擊這裏 【思路】 最長公共子序列的元素變成了單詞,算法依然相同。最後輸出子序列時,只需根據ans數組從後往前索引,遇到序列元素時就將其入棧,最後出棧輸出。 【代碼】 #include <stdio.h> #include <s

原创 poj_2752 Seek the Name, Seek the Fame(KMP:尋找所有公共前綴後綴)

【題目描述】 The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to

原创 poj_3630 Phone List(Trie樹練習)

【題目】 點擊這裏 【思路】 基本的Trie樹應用,作爲回顧練習。判斷是否有重號的依據:在建樹過程中,找到重複串或者在葉子節點繼續插入,當且僅當有重號。 【代碼】 #include <stdio.h> #include <string.h

原创 The Postorder enumeration(二叉樹遍歷:前中轉後)

【題目描述】 Give you the Preorder enumeration and Inorder enumeration of a binary tree, output its Postorder enumeration. W

原创 poj_2406 Power Strings(KMP求週期子串)

【題目描述】 Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then

原创 poj_1458 Common Subsequence(最長公共子序列)

【題目】 點擊這裏 【思路】 經典的LCS問題,動態規劃即可,狀態轉移方程: 【代碼】 #include<stdio.h> #include<string.h> #define size 220 #define max(x,y) x>

原创 Calculator(後綴表達式)

【題目要求】 Implement a calculator program based on a Reverse Polish notation. 【輸入】 There could be several lines. Each line

原创 poj_3450 Corporate Identity(KMP+枚舉)

【題目】 點擊這裏 【思路】 同poj_3080 Blue Jeans,依然秒AC(1100ms << 3000ms demanded) 【代碼】 #include <stdio.h> #include <string.h> char

原创 poj_3461 Oulipo(KMP:找出所有模式串)

本題就是經典的模式串匹配問題,只需要對上文中的程序稍作修改即可。(hihoCoder上的KMP算法一題,與本題一模一樣) #include <stdio.h> #include <string.h> void getNext(char

原创 Big vs Big(鏈表)

【題目描述】 Calculate the addtion of any two positive big integers. Requirements: Test data can be more than 64 digits, ther

原创 poj_2418 Hardwood Species (字典序Trie樹)

又是一道典型的Trie樹應用題,有了Trie樹的基本知識,寫起來就非常容易了~~ 【題目描述】 Hardwoods are the botanical group of trees that have broad leaves, prod

原创 poj_3080 Blue Jeans(KMP應用)

【題目】 點擊這裏 【思路】 按照長度從大到小的順序,枚舉第一個串的子串,每次都嘗試將此子串與其他串匹配,直至所有匹配都成功。注意最後輸出的是,長度儘可能大且字典序最小的子串。 原本以爲時間上可能有壓力,沒想到KMP算法效率非常高,枚舉+

原创 hihoCoder_W84 Lucky Substrings(基礎做法)

【題目】 點擊這裏 【思路】 分兩步走,1. 找出所有斐波那契子串;2. 按字典序無重複地輸出。 第一步可以枚舉子串,由於規模比較小,O(n^2)的算法都可以接受。O(n^3)優化至O(n^2)的方法是,從前往後枚舉子串,[i…j+1]可

原创 Rail station(棧)

【題目】 There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in las

原创 poj_2506 Tiling(高精度加法)

【題目】 點擊這裏 【思路】 很容易想到遞推 f[n]=f[n-1]+2*f[n-2]。之後的事情,就是高精度加法了。 【代碼】 #include <stdio.h> int n, total, ans[251][80]; void