題意:求n個串在乙個很長的串中出現的次數。
思路: 典型的ac自動機模板題。
細節參見**:
#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const ld eps = 1e-9, pi = 3.1415926535897932384626433832795;
const int mod = 1000000000 + 7;
const int inf = 0x3f3f3f3f;
const int maxs = 1000000*2 + 10;
// & 0x7fffffff
const int seed = 131;
const int sigma_size = 199;
const ll inf64 = ll(1e18);
const int maxn = 100;
const int maxnode = 1000*55 + 10;
int t,n,m;
int ch[maxnode][sigma_size];
int f[maxnode]; // fail函式
int val[maxnode]; // 每個字串的結尾結點都有乙個非0的val
int last[maxnode]; // 輸出鍊錶的下乙個結點
int cnt[maxs];
int sz;
mapms;
void init()
// 字元c的編號
int idx(char c)
// 插入字串。v必須非0
void _insert(char *s, int v)
u = ch[u][c];
}val[u] = v;
// ms[string(s)] = v;
} // 遞迴列印以結點j結尾的所有字串
void print(int j)
}// 在t中找模板
void _find(char* t)
}// 按bfs順序計算fail
while(!q.empty())
}}char buf[1006][55];
char s[2000000 + 10];
int main()
getfail();
scanf("%s",s);
_find(s);
for(int i=1;i<=n;i++)
}return 0;
}
hdu 3065 病毒侵襲持續中
題目大意及思路 ac自動機。include include include include include include include include include include includeusing namespace std define inf 0x3f3f3f3f define ...
HDU 3065 病毒侵襲持續中
這就更簡單了,都不用把out標記成false了 題目中的病毒都是大寫字母這個條件應該怎麼用?include include include include include include include include include include include include include ...
HDU 3065 病毒侵襲持續中
詢問每個模式串在文字傳中出現的次數。文字串中出現的字元不一定都是大寫字母,只需要在匹配的時候,對文字串進行特殊處理,將連續的大寫字母段當成合法的乙個文字串即可。然後 就是簡單的統計了。include include include include include include using name...