记录编号 553308 评测结果 AAAAAAAAAA
题目名称 词链 最终得分 100
用户昵称 Gravatarfsdh 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2020-08-17 12:44:31 内存使用 1.69 MiB
显示代码纯文本
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 10010;
int n;
int dp[MAXN];
class node {
	public :
		bool vis;
		node *next[26];
		int index;
	node () {
		index = 0;
		vis = false;
		memset (next,0,sizeof (next));
	}
};
void insert (node *p,char *s,int num) {
	int len = strlen (s);
	for (int q = 0;q < len;++ q) {
		int x = s[q] - 'a';
		if (p -> next[x] == NULL) p -> next[x] = new node ();
		if (p -> index != 0) {
			dp[num] = max (dp[num] ,dp[p -> index] + 1);
		}
		p = p -> next[x];
	}
	p -> vis = true;
	p -> index = num;
	return ;
}
bool query (node *p,char *s) {
	int len = strlen (s);
	for (int q = 0;q < len;++ q) {
		int x = s[q] - 'a';
		if (p -> next[x] == NULL) return false;
		p = p -> next[x];
	}
	return p -> vis;
}
node *root;
int ans = -1;
int main () {
	freopen("link.in","r",stdin);
	freopen("link.out","w",stdout);
	root = new node ();
	scanf("%d",&n);
	char s[61];
	for (int q = 1;q <= n;++ q) {
		dp[q] = 1;
		scanf("%s",s);
		insert (root ,s ,q);
	}
	for (int q = 1;q <= n;++ q) {
		ans = max (ans ,dp[q]);
	}
	printf ("%d\n",ans);
	return 0;
}