E carper kmp+滑动窗口 求二维矩阵的最小循环,并且令该循环区间的最大值最小
链接:https://ac.nowcoder.com/acm/problem/16638
来源:牛客网
题目描述
White Cloud has a rectangle carpet of n∗mn*mn∗m. Grid(i,j)Grid (i,j)Grid(i,j) has a color colorA[i][j]colorA[i][j]colorA[i][j] and a cost costA[i][j]costA[i][j]costA[i][j].
White Rabbit will choose a subrectangle BBB of p∗qp*qp∗q from AAA and the color of each grid is colorB[0...p−1][0...q−1]colorB[0...p-1][0...q-1]colorB[0...p−1][0...q−1], the cost of BBB is the (maximum number in the corresponding subrectangle of costA∗(p+1)∗(q+1)costA*(p+1)*(q+1)costA∗(p+1)∗(q+1)).
Then colorBcolorBcolorB is continuously translated and copied in an infinite times, that is, expand colorBcolorBcolorB into an infinite new matrix, colorCcolorCcolorC, which satisfies colorC[i][j]=colorB[imodp][jmodq]colorC[i][j]=colorB[i mod p][j mod q]colorC[i][j]=colorB[imodp][jmodq].
White Rabbit must ensure that colorAcolorA
White Rabbit will choose a subrectangle BBB of p∗qp*qp∗q from AAA and the color of each grid is colorB[0...p−1][0...q−1]colorB[0...p-1][0...q-1]colorB[0...p−1][0...q−1], the cost of BBB is the (maximum number in the corresponding subrectangle of costA∗(p+1)∗(q+1)costA*(p+1)*(q+1)costA∗(p+1)∗(q+1)).
Then colorBcolorBcolorB is continuously translated and copied in an infinite times, that is, expand colorBcolorBcolorB into an infinite new matrix, colorCcolorCcolorC, which satisfies colorC[i][j]=colorB[imodp][jmodq]colorC[i][j]=colorB[i mod p][j mod q]colorC[i][j]=colorB[imodp][jmodq].
White Rabbit must ensure that colorAcolorA