Question Link
Question:A ring matrix is given, that is, the first row is connected to the last row. The first column is connected to the last column, and the sum of the largest child matrix is obtained.
Ideas:As long as four matrices are copied, the sum of the maximum submatrices in a matrix can be obtained, that is, the sum of all submatrices is enumerated and the maximum value is updated. Note that in the converted large matrix, the Child matrix of enumeration has a range.
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int INF = 0x3f3f3f; const int maxn = 205; int arr [maxn] [maxn], sum [maxn]; int N, Max; int deal () {int temp; For (INT I = 0; I <N; I ++) {for (Int J = 0; j <n; j ++) {memset (sum, 0, sizeof (SUM); For (int K = I; k <I + N; k ++) {temp = 0; For (INT L = J; L <j + N; l ++) {sum [l] + = arr [k] [l]; temp + = sum [l]; If (max <temp) max = temp ;}}}} return Max;} int main () {int CAS; scanf ("% d", & CAS); While (CAS --) {scanf ("% d", & N ); for (INT I = 0; I <n; I ++) {for (Int J = 0; j <n; j ++) {scanf ("% d ", & arr [I] [J]); arr [I] [J + N] = arr [I + N] [J] = arr [I + N] [J + N] = arr [I] [J]; }} max =-INF; int ans = deal (); printf ("% d \ n", ANS);} return 0 ;}