为什么python在函数中修改"字典型global全局变量量"不需要global

数据结构(62)
字符串(15)
//======================
// HDU 2222
// 求目标串中出现了几个模式串
//====================
#include &stdio.h&
#include &algorithm&
#include &iostream&
#include &string.h&
#include &queue&
struct Trie
int next[],fail[500010],end[500010];
int root,L;
int newnode()
for(int i = 0;i & 26;i++)
next[L][i] = -1;
end[L++] = 0;
return L-1;
void init()
root = newnode();
void insert(char buf[])
int len = strlen(buf);
for(int i = 0;i &i++)
if(next[now][buf[i]-'a'] == -1)
next[now][buf[i]-'a'] = newnode();
now = next[now][buf[i]-'a'];
end[now]++;
void build()
queue&int&Q;
fail[root] =
for(int i = 0;i & 26;i++)
if(next[root][i] == -1)
next[root][i] =
fail[next[root][i]] =
Q.push(next[root][i]);
while( !Q.empty() )
int now = Q.front();
for(int i = 0;i & 26;i++)
if(next[now][i] == -1)
next[now][i] = next[fail[now]][i];
fail[next[now][i]]=next[fail[now]][i];
Q.push(next[now][i]);
int query(char buf[])
int len = strlen(buf);
int res = 0;
for(int i = 0;i &i++)
now = next[now][buf[i]-'a'];
int temp =
while( temp != root )
res += end[temp];
end[temp] = 0;
temp = fail[temp];
void debug()
for(int i = 0;i & L;i++)
printf(&id = %3d,fail = %3d,end = %3d,chi = [&,i,fail[i],end[i]);
for(int j = 0;j & 26;j++)
printf(&%2d&,next[i][j]);
printf(&]\n&);
char buf[1000010];
int main()
scanf(&%d&,&T);
while( T-- )
scanf(&%d&,&n);
ac.init();
for(int i = 0;i &i++)
scanf(&%s&,buf);
ac.insert(buf);
ac.build();
scanf(&%s&,buf);
printf(&%d\n&,ac.query(buf));
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:80707次
积分:3784
积分:3784
排名:第7088名
原创:293篇
转载:40篇
(1)(1)(2)(2)(12)(12)(3)(1)(1)(5)(22)(36)(4)(15)(21)(25)(20)(14)(10)(30)(22)(58)(12)(5)数学(27)
struct Matrix{
int mat[15][15];
void init(int _n){
memset(mat,0,sizeof(mat));
Matrix operator *(const Matrix &b)const{
ret.init(n);
for(int i = 0;i &i++)
for(int j = 0;j &j++){
ret.mat[i][j] = 0;
for(int k = 0;k &k++){
ret.mat[i][j] += (long long)mat[i][k]*b.mat[k][j]%MOD;
if(ret.mat[i][j] &= MOD)
ret.mat[i][j] -= MOD;
Matrix pow_M(Matrix a,long long n){
Matrix tmp =
ret.init(a.n);
for(int i = 0;i & a.n;i++)ret.mat[i][i] = 1;
if(n&1)ret = ret*
tmp = tmp*
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:80708次
积分:3784
积分:3784
排名:第7088名
原创:293篇
转载:40篇
(1)(1)(2)(2)(12)(12)(3)(1)(1)(5)(22)(36)(4)(15)(21)(25)(20)(14)(10)(30)(22)(58)(12)(5)

我要回帖

更多关于 python 全局字典 的文章

 

随机推荐