1174: [Balkan2007]Toponyms
来源:互联网 发布:91手机助手mac版 编辑:程序博客网 时间:2024/06/05 10:36
题目链接
题目大意:有一个字符集合,从其中找一些字符串出来,最大化这些字符串的LCP长度*字符串个数
题解:稍有常识的人就能看出,这是一道Trie树裸题,在插入的时候顺手统计答案就可以了
然而这题卡空间,需要用邻接表存储
我的收获:……
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <algorithm>#include <vector>using namespace std;int read() { int x = 0, f = 1; char c = getchar(); while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); } while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); } return x * f;}#define maxn 5000010#define LL long longint n, rt, ToT, m, val[maxn], head[maxn], nxt[maxn], to[maxn];char ec[maxn];LL ans;void insert() { int u = rt; val[u]++; char C = getchar(); for(int i = 0; C != '\n'; i++, C = getchar()) { int v = -1; for(int e = head[u]; e; e = nxt[e]) if(ec[e] == C){ v = to[e]; break; } if(v < 0) to[++m] = ++ToT, ec[m] = C, nxt[m] = head[u], head[u] = m, v = ToT; val[u = v]++; ans = max(ans, (LL)val[u] * (i + 1)); } return ;}int main() { n = read(); rt = ToT = 1; for(int i = 1; i <= n; i++) insert(); printf("%lld\n", ans); return 0;}
阅读全文
0 0
- BZOJ 1174: [Balkan2007]Toponyms
- 1174: [Balkan2007]Toponyms
- BZOJ P1174[Balkan2007]Toponyms
- 求助:BZOJ 1174: [Balkan2007]Toponyms (隐藏题)
- bzoj11741174: [Balkan2007]Toponyms 字典树
- BZOJ1174 [Balkan2007] Toponyms 邻接链表优化 TRIE树
- 【Balkan2007】Mokia
- 【BZOJ 1176】 [Balkan2007]Mokia
- bzoj 1176: [Balkan2007]Mokia
- 1176: [Balkan2007]Mokia
- [BZOJ1176] [Balkan2007]Mokia
- BZOJ1170 Balkan2007 Cipher
- BZOJ1173 Balkan2007 Point
- BZOJ1170: [Balkan2007]Cipher|hash
- 【bzoj1176】[Balkan2007]Mokia
- bzoj1176: [Balkan2007]Mokia
- bzoj1176【Balkan2007】Mokia
- BZOJ 1172 Balkan2007 Dream
- 2298: [HAOI2011]problem a
- 对象的深浅拷贝方法
- VMWare安装linux系统
- 2134: 单选错位
- 2017 Multi-University Training Contest
- 1174: [Balkan2007]Toponyms
- HDU 5094 Maze & HDU 4845 拯救大兵瑞恩 (BFS + 状压)
- 深入理解计算机操作系统(2.1.1、2.1.2)
- WebGIS学习(五)-WebGIS中通过行列号来换算出多种瓦片的URL 之在线地图
- 1295: [SCOI2009]最长距离
- 待学事项
- JSON书写格式
- 凸分析(1)
- 生产者-消费者问题详解