BZOJ 1174: [Balkan2007]Toponyms

1174: [Balkan2007]Toponyms

Time Limit: 10 Sec   Memory Limit: 128 MB 
Submit: 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

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代码那就大错特错了,但你不妨认为这是对的,哈哈哈哈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值