Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
139161 周震东 单词接龙 C++ 通过 100 0 MS 576 KB 820 2024-03-21 19:27:43

Tests(5/5):


#include <bits/stdc++.h> using namespace std; int n,Len,Max; int used[100001],l[100001]; string s[10001]; int Find(int a, int b) { for(int i=l[a]-1; i>=1; i--) if(s[a][i] == s[b][0]) { for(int j=i+1,k=1; j<=l[a]-1; j++,k++) if(s[a][j] != s[b][k]) return 0; return l[b]- (l[a]-i); } return 0; } void Dfs(int x) { for(int i = 1; i <= n; i++) if(used[i] < 2 && Find(x, i)) { used[i]++; Len += Find(x, i); Dfs(i); used[i]--; Len -= Find(x, i); } Max=max(Max,Len); } int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { cin>>s[i]; l[i] = s[i].length(); } char ch; cin>>ch; for(int i = 1; i <= n; i++) if(s[i][0] == ch) { Len = l[i]; used[i]++; Dfs(i); used[i]--; } printf("%d\n", Max); return 0; }


测评信息: