求助:BZOJ 1174: [Balkan2007]Toponyms (隐藏题)

来源:互联网 发布:c语言什么书好 编辑:程序博客网 时间:2024/06/15 02:42

Description

给你一个字符集合,你从其中找出一些字符串出来. 希望你找出来的这些字符串的最长公共前缀*字符串的总个数最大化.

Input

第一行给出数字N.N在[2,1000000] 下面N行描述这些字符串,长度不超过20000 总输入不超过20000字符

Output

 a single line with an integer representing the maximal level of complexityLc(T).

Sample Input

7
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi

Sample Output

24

 

我的代码是RE,请问各位神犇这是为什么。就算我数组开到将近3000万也是RE。

#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<cmath>using namespace std;char a[20005];int n,size,tire[20002][60],cs[20002],ans;int change(char x){if(x==' ') return 52;else if(x<='Z') return x-'A';else return  x-'a'+26;}void insert(){int w=0,l=strlen(a),p=0,k;//printf("%d\n",l);while(p<l)   {k=change(a[p]);    if(!tire[w][k]) tire[w][k]=++size;    w=tire[w][k];  cs[w]++;ans=max(ans,cs[w]*(p+1)); p++;   }}int main(){scanf("%d\n",&n);for(int i=1;i<=n;i++)   {gets(a);    //printf("%s\n",a);    insert();   }printf("%d\n",ans);//system("pause");return 0;}

0 0
原创粉丝点击