题目传送门
解题思路:
好水的题.
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<map> 4 5 using namespace std; 6 7 map<string,int> f; 8 int n,ans = 1; 9 string l[2001]; 10 11 inline int max(int a,int b) { 12 if(a >= b) return a; 13 return b; 14 } 15 16 int main() { 17 scanf("%d",&n); 18 for(int i = 1;i <= n; i++) { 19 cin >> l[i]; 20 f[l[i]] = 0; 21 } 22 for(int i = 1;i <= n; i++) { 23 for(int j = 1;j < l[i].length(); j++) { 24 string o = l[i].substr(0,j); 25 if(f.count(o)) 26 f[l[i]] = max(f[l[i]],f[o] + 1); 27 } 28 if(f[l[i]] == 0) f[l[i]] = 1; 29 ans = max(ans,f[l[i]]); 30 } 31 printf("%d",ans); 32 return 0; 33 }