题解
1.由于我刚刚才学字典树,所以我会告诉你这就类似字典树,对字符串终点节点加一,然后搜索统计最大前缀和
code
#include<bits/stdc++.h>
using namespace std;
string s;
int tree[2000005][65]={0};
int num=0;
int cnt[2000005]={0};
int inshe(char a)
{
if(a>='a'&&a<='z') return a-'a'+1;
else if(a>='A'&&a<='Z') return a-'A'+1+26;
else return a-'0'+1+52;
}
void add()
{
int now=0;
for(int i=0;s[i];i++)
{
int son=inshe(s[i]);
if(!tree[now][son]) tree[now][son]=++num;
now=tree[now][son];
}
cnt[now]++;
}
int ss()
{
queue<int> q;
q.push(0);
int ans=0;
while(q.size())
{
int now=q.front();
q.pop();
ans=max(ans,cnt[now]);
for(int i=1;i<=62;i++)
if(tree[now][i])
{
int next=tree[now][i];
cnt[next]+=cnt[now];
q.push(next);
}
}
return ans;
}
int main()
{
int n;
cin>>n;
while(n--)
{
cin>>s;
add();
}
cout<<ss();
return 0;
}
标签:2000005,cnt,P1481,密码,int,魔族,&&,ans
From: https://www.cnblogs.com/pure4knowledge/p/18105999