题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头。开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行处理,也是,通过补全一个相同的,问题就迎刃而解了,所以把n*n的矩阵扩展成2n*2n的矩阵就好了。

 #include <cstdio>
#include <cstring>
#define MAXN 160 int a[MAXN][MAXN], sum[MAXN][MAXN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--)
{
int n;
scanf("%d", &n);
memset(sum, , sizeof(sum));
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
scanf("%d", &a[i][j]);
for (int j = n+; j <= *n; j++)
a[i][j] = a[i][j-n];
}
for (int i = n+; i <= *n; i++)
for (int j = ; j <= *n; j++)
a[i][j] = a[i-n][j];
for (int i = ; i <= *n; i++)
for (int j = ; j <= *n; j++)
sum[i][j] = sum[i][j-] + sum[i-][j] - sum[i-][j-] + a[i][j];
int max = a[][];
for (int i = ; i <= n; i++)
for (int p = ; p < n; p++)
for (int j = ; j <= n; j++)
for (int q = ; q < n; q++)
{
int t = sum[i+p][j+q] - sum[i+p][j-] - sum[i-][j+q] + sum[i-][j-];
if (t > max) max = t;
}
printf("%d\n", max);
}
return ;
}

最新文章

  1. 利用Mongoose来结构化模式与验证
  2. salt stack 工具之一——远程命令
  3. Install MySQL on Mac by Homebrew
  4. 为AM335x移植Linux内核主线代码(35)使用platform中的GPIO
  5. spider autohome (1)
  6. ruby include和exclude区别
  7. mysql innobackupex xtrabackup 大数据量 备份 还原(转)
  8. SqlServer维护计划
  9. 【python之旅】python简介和入门
  10. paip.Adblock屏蔽规则保存位置以及修理恢复
  11. shell编程其实真的很简单(四)
  12. 极大似然估计(MLE)
  13. Beta Scrum Day 2
  14. TCP和UDP的最完整的区别
  15. 浅析HSTS
  16. [20180810]exadata--豆腐渣系统的保护神.txt
  17. const关键字的作用
  18. BZOJ1127 POI2008KUP(悬线法)
  19. 广播消费:允许一个 Group ID 所标识的所有 Consumer 都会各自消费某条消息一次。
  20. topcoder srm 470 div1

热门文章

  1. jQuery两种扩展插件的方式
  2. hdu_3886_Final Kichiku “Lanlanshu”(数位DP)
  3. awk 数组排序-- asort 与 asorti
  4. MySQL与MongoDB之SQL语法对比
  5. HDFS在Linux下的命令
  6. java网络之tcp
  7. Android之实战篇(三)
  8. j2ee常用包的作用
  9. hrbustoj 1985(进制转换函数)
  10. PAT (Advanced Level) 1068. Find More Coins (30)