本文主要是介绍UVA - 10827 Maximum sum on a torus,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:Maximum Sum 的加强版,多了个可以构成环,那么就把图扩大成4倍,然后枚举每种情况
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 210;int a[MAXN][MAXN],b[MAXN];int main()
{int n,t;scanf("%d",&t);while (t--){scanf("%d",&n);for (int i = 0; i < n; i++)for (int j = 0; j < n; j++){scanf("%d",&a[i][j]);a[i+n][j] = a[i][j+n] = a[i+n][j+n] = a[i][j];}int Max = -123456675;for (int i = 0; i < n; i++)for (int j = 0; j < n; j++){memset(b,0,sizeof(b));for (int x = 0; x < n; x++){int sum = 0;for (int y = 0; y < n; y++){b[y+j] += a[x+i][j+y];sum += b[y+j];if (sum > Max)Max = sum;}} }printf("%d\n",Max); }return 0;
}
这篇关于UVA - 10827 Maximum sum on a torus的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!