标签:
5
i
int
integer
intern
internet
4
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> using namespace std; struct dat{ int Hash; int id; }tmp; const int sed = 31,Sed = 131,mod = 70177,Mod = 92311; int n,l[2005],ans,f[2005]; char a[2005][105]; vector<dat> h[mod]; int main(){ cin>>n; for(int i = 1;i <= n;i++){ scanf("%s",a[i] + 1); a[i][0] = ‘!‘; l[i] = strlen(a[i]) - 1; int hash = 0,Hash = 0; for(int j = 1;j <= l[i];j++){ hash = (hash * sed + a[i][j]) % mod; Hash = (Hash * Sed + a[i][j]) % Mod; } tmp.Hash = Hash; tmp.id = i; h[hash].push_back(tmp); } for(int i = 1;i <= n;i++){ f[i] = 1; int hash = 0,Hash = 0; for(int j = 1;j < l[i];j++){ hash = (hash * sed + a[i][j]) % mod; Hash = (Hash * Sed + a[i][j]) % Mod; for(int k = 0;k < h[hash].size();k++){ if(h[hash][k].Hash == Hash) f[i] = max(f[i],f[h[hash][k].id] + 1); } } ans = max(ans,f[i]); } cout<<ans; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5791416.html