Preprocess the data first. Similar to the request LCS
And then check the set
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <string>6#include <queue>7#include <algorithm>8#include <map>9#include <iomanip>Ten#include <climits> One#include <string.h> A#include <cmath> -#include <stdlib.h> -#include <vector> the#include <stack> -#include <string.h> -#include <Set> - #defineINF 1e7 + #defineMAXN 10010 - #defineMAXN 1000010 + #defineMod 1000007 A #defineN 110 at using namespacestd; -typedefLong LongLL; - - intN; - Doublem; - CharStr[n][n]; in intFa[n], len[n], dp[n][n]; - to intFindset (intx) + { - returnFA[X] = fa[x] = = x?X:findset (fa[x]); the } * $ intGetlen (intAintb)Panax Notoginseng { - intRe =0; thememset (dp[0],0,sizeof(dp[0])); + for(inti =1; I <= Len[a]; i++) A { thedp[i][0] =0; + for(intj =1; J <= Len[b]; J + +) - { $ if(Str[a][i] = = Str[b][j]) dp[i][j] = dp[i-1][j-1] +1; $ ElseDP[I][J] =0; - if(Re < dp[i][j]) Re =Dp[i][j]; - } the } - returnre;Wuyi } the intMain () - { Wu intT =1; - intx, Y, L; About while(Cin >> N >>m) $ { - for(inti =0; I < n; i++) -Fa[i] =i; - for(inti =0; I < n; i++) A { +scanf"%s", Str[i] +1); thestr[i][0] =' '; -Len[i] = strlen (Str[i])-1; $ for(intj =0; J < I; J + +) the { the intx =Findset (i); the inty =Findset (j); the if(x = = y)Continue; -L =Getlen (i, j); in if(l*100.0/len[i] > M && l*100.0/LEN[J] >m) theFA[X] =y; the } About } the intAns =0; the for(inti =0; I < n; i++)if(Fa[i] = = i) ans++; theprintf"Case %d:\n%d\n", t++, ans); + } - return 0; the}
Hdu 2144 Evolution (Ji +DP)