Uva10827-maximum sum on a torus (Matrix Max and deform)

Source: Internet
Author: User

Uva10827-maximum sum on a torus (maximum and deformation of matrices)


The main idea: is uva108 deformation, the matrix can be connected, is able to connect from the back to the front. Here The matrix is copied three times, and then once again generate a large matrix, you can solve the problem of Unicom. Then enumerate the starting and ending points of the matrix, preserving the maximum value.

For example: 1 2 3

2 3 4

New matrix: 1 2 3 1 2 3

2 3 4 2 3 4

1 2 3 1 2 3

2 3 4 2 3 4


Code:

#include <stdio.h> #include <string.h>const int N = 200;const int INF = 0x3f3f3f3f;int Mat[n][n], temx[n], Temy [N];int n;int Max (const int x, const int y) {return x > y? x:y;} int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%d", &n), as (int i = 0; i < n; i++) for (int j = 0; j < n; J + +) {scanf ("%d", &mat[i][j]), Mat[i][j + n] = mat[i + N][j] = mat[i + n][j + n] = mat[i][j];}  int mm =-inf;for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {memset (temx, 0, sizeof (TEMX)); for (int x = I x < i + N; X + +) {for (int y = j; y < J + N; y++) {if (y = = j) Temy[y] = mat[x][y];elsetemy[y] = temy[y-1] + mat[x][y];temx[y] + = TEMY[Y];MM = max (mm, temy[y]); mm = max (mm, temx[y]);}}} printf ("%d\n", mm);} return 0;}


Uva10827-maximum sum on a torus (Matrix Max and deform)

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.