原创 1251 字典樹 模板

參考資料 : http://www.wutianqi.com/?p=1359 http://blog.csdn.net/xingyeyongheng/article/category/1516007 #include <iostream

原创 KMP

參考:  http://www.cnblogs.com/BeyondAnyTime/archive/2012/07/09/2583133.html         http://blog.csdn.net/v_july_v/article

原创 hdu 3068 迴文串

#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 110010; char b[maxn],

原创 hdu1203 01揹包

至少得反面是一個沒有 所以方程爲 max(dp[j], 1-(1-dp[j-v[i]])*(1-c[i])) #include <iostream> #include <cstdio> #include <cstring> using

原创 hdu 2203 親和串

思路:如果第一個串長度小於第二個就no 將第一個串後面加上第一個串前x個字符 (x是第二個串的長度); 因爲如果這樣還不能匹配就循環多少都不會匹配; #include <iostream> #include <cstring> #in

原创 hdu 2955 01揹包

按照01 揹包知道 概率應該作爲揹包 但是浮點型不能直接減, 所以轉換下 將錢的總和作爲揹包 被抓的概率轉換爲不被抓的概率 作爲價值; #include <iostream> #include <cstdio> #include <c

原创 hdu 2594 Simpsons’ Hidden Talents

方法一: 題意:求兩個串的前綴和後綴最大的長度, 思路:將第一個串作爲模式串 第二個作爲原串,進行KMP 當 i == len1 作爲結束條件 #include <iostream> #include <cstdio> #includ

原创 hdu 2802 找循環節 的方法

#include <iostream> #include <cstdio> using namespace std; int f[5000]; int main() { f[1] = 1; f[2] = 7; in

原创 hdu 2846 經典字典樹

思路:因爲字典樹只能讀取前綴有多少個相同的, 對於求子串可以將字符串分成 多個字串看成單獨的字符串 進行建 字典樹,但要注意這兩個字符串 abab, ab 他們的字串都有 ab a 所以在建樹時 判斷是否同一個字符串 不同就加 1 ;

原创 poj 3974

#include <iostream> #include <cstdio> using namespace std; const int maxn = 1e6+10; char b[maxn], a[maxn<<1]; int p[max

原创 SGU 180. Inversions 離散 + 樹狀數組

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 700

原创 hdu 1711 KMP

#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1e6+9; const int maxn1 =

原创 hdu1686

#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1000000+9; const int max

原创 hdu 1075 字典樹

在建樹的時候記錄每個火星單詞對應的英語單詞位置,在查找時候輸出 相應的位置 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> u

原创 hdu 1671 字典樹 模板

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> struct Trie { int num; Trie *nex