Uva10827-maximum sum on a Torus

Source: Internet
Author: User

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.


# 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.