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

Description

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

Input

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

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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值