最大和 -- 最大子矩阵

从一维的最大子序列 , 到二维的最大子序列 , 实际上还是转化为一维的去计算 , 通过输入时获得操作 , 和下面的 三个 for 循环 得以 计算最大子序列 /

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<vector>
 8 #include<set>
 9 #include<stack>
10 #include<string>
11 #include<sstream>
12 #include<map>
13 #include<cctype>
14 #include<limits.h>
15 using namespace std;
16 int main()
17 {
18     int t,a[2][6],n,m;
19     scanf("%d",&t);
20     while(t--)
21     {
22         scanf("%d%d",&n,&m);
23         memset(a,0,sizeof(a));
24         for(int i=1;i<=n;i++)
25             for(int j=1;j<=m;j++)
26             {
27                 scanf("%d",&a[i][j]);
28                 a[i][j]=a[i][j]+a[i-1][j]; //   这里是一个重要的处理 ,  让下面的数据 , 代表该数据及以上数据之和  便于下方计算
29             }
30         int temp,result=INT_MIN;
31         for(int i=1;i<=n;i++)     //            通过这三个  for 循环 得以计算到  最大值的最小子序列 . 
32             for(int j=i;j<=n;j++)
33             for(int k=1,maxn=INT_MIN;k<=m;k++)
34         {
35             temp=a[j][k]-a[i-1][k];
36             maxn=(maxn>0?maxn:0)+temp;
37             result=maxn>result?maxn:result;
38         }
39         printf("%d\n",result);
40     }
41     return 0;
42 }

 

转载于:https://www.cnblogs.com/A-FM/p/5462515.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值