利用了kmp的性質,kmp可以找出前i個在主串出現的次數(可覆蓋),同樣也可以找出後j個在主串出現的次數,只需要反向kmp就行了==,具體實現是兩次預先處理正向&反向,然後記錄num1和num2數組所以複雜度是線性時間.....理解kmp是重點!#define N 100005char s[N],t[N];int next1[N],next2[N];int num1[N],num2[N];//記錄i左邊在主串出現次數和i右邊的int l1,l2;void gao1(){ int
轉自百度百科KM演算法用來解決最大權匹配問題: 在一個二分圖內,左頂點為X,右頂點為Y,現對於每組左右串連XiYj有權wij,求一種匹配使得所有wij的和最大。基本原理 該演算法是通過給每個頂點一個標號(叫做頂標)來把求最大權匹配的問題轉化為求完備匹配的問題的。設頂點Xi的頂標為A[ i ],頂點Yj的頂標為B[ j ],頂點Xi與Yj之間的邊權為w[i,j]。在演算法執行過程中的任一時刻,對於任一條邊(i,j),A[ i
http://poj.org/problem?id=3160方法:tarjan縮點+topsort+dp,注意這句話. To save vigor, flymouse decided to choose only one of those rooms as the place to start his journey and follow directed paths to visit one room after another and give out gifts en passant
http://acm.hdu.edu.cn/showproblem.php?pid=1879 #include<stdio.h> #include<string> #define MAX 0x3fffffff int map[101][101],dis[101],vis[101]; int main() { int n; freopen("a.txt","r",stdin);
Following OrdersTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2194 Accepted: 794DescriptionOrder is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which every
TreasureTime Limit: 2000 ms Memory Limit: 65535 kBSolved: 68 Tried: 140 Description Loneknight is finding treasures in a maze. He is so greedy that he always takes away all the treasure he can reach. Now, he has a map for the maze, and he want to
http://poj.org/problem?id=3678【題意】:有n個變數,每個可以取0或者1,再給出m組關係,每組關係都是兩個變數進行運算可以得到的結果,運算有AND OR XOR三種,問能否根據這些關係,判斷每個變數的取值。【題解】:2-Sat問題,關鍵是要把所有情況考慮完全。用x表示該變數取0,x’表示取1,下面說下如何構圖: a and b == 1, 這種情況a和b必須取1,所以連邊a->a', b->b'.(保證合法時a b一定取1)