1174: [Balkan2007]Toponyms
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 604 Solved: 78
[ Submit ][ Status ][ Discuss ]
Description
给你一个字符集合,你从其中找出一些字符串出来. 希望你找出来的这些字符串的最长公共前缀*字符串的总个数最大化.
Input
第一行给出数字NN在[2,1000000]下面N行描述这些字符串,长度不超过20000 。保证输入文件不超过10MB
Output
a single line with an integer representing the maximal level of complexity Lc ( T ).
Sample Input
7
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi
Sample Output
24
字典树,然而我必须说这是一个错误的代码,此题卡空间,各位珍重
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
const int N=20010;
int n,tot,tr[N<<6][60],w[N<<6],ans=0;
string str;
inline void insert()
{
int k,now=0,len=str.length();
for(int i=0;i<len;i++)
{
if(str[i]==' ')k=52;
else if(str[i]<='Z')k=str[i]-'A';
else k=str[i]-'a'+26;
if(!tr[now][k])tr[now][k]=++tot;
now=tr[now][k];w[now]++;
ans=max(ans,w[now]*(i+1));
}
}
int main()
{
n=read();
while(n--)
{getline(cin,str);insert();}
printf("%d\n",ans);
}
如果你认为这是一个AC代码那就大错特错了,但你不妨认为这是对的,哈哈哈哈