Poj2185 Milking Grid (minimum coverage matrix)
// A matrix composed of characters is given, and the minimum coverage matrix is obtained. // The length of the minimum covering substring in each row can be obtained. As long as the minimum length is obtained, the width of the minimum coverage matrix is obtained. // Similarly, find the length of the minimum covering substring in each column, and then find the minimum public multiple to obtain the height of the minimum covering matrix. # Include
# Include
# Include using namespace std; char a [10010] [100]; int next [10010]; int n, m; int Getnext1 (int r) {int I = 0, j =-1; next [0] =-1; while (I <= m) {if (j =-1 | a [r] [I] = a [r] [j]) I ++, j ++, next [I] = j; else j = next [j];} return m-next [m];} int Getnext2 (int r) {int I = 0, j =-1; next [0] =-1; while (I <= n) {if (j =-1 | a [I] [r] = a [j] [r]) I ++, j ++, next [I] = j; else j = next [j];} return n-next [n];} int lcm (int a, int B) // minimum public Multiple Template {int mul = A * B; int r = a % B; while (r) {a = B; B = r; r = a % B;} return mul/B ;} int main () {int I, ans2, ans1; while (~ Scanf ("% d", & n, & m) {for (I = 0; I
M) {ans1 = m; break;} for (I = 0; I
N) {ans2 = n; break;} printf ("% d \ n", ans1 * ans2);} return 0 ;}