51Nod 1158 全是1的最大子矩阵

                       1158 全是1的最大子矩阵
基准时间限制:1 秒 空间限制:131072 KB 分值: 80  难度:5级算法题
 收藏
 关注
给出1个M*N的矩阵M1,里面的元素只有0或1,找出M1的一个子矩阵M2,M2中的元素只有1,并且M2的面积是最大的。输出M2的面积。
 
Input
第1行:2个数m,n中间用空格分隔(2 <= m,n <= 500)
第2 - N + 1行:每行m个数,中间用空格分隔,均为0或1。
Output
输出最大全是1的子矩阵的面积。
Input示例
3 3
1 1 0
1 1 1
0 1 1
Output示例
4
李陶冶  (题目提供者)
 
 水题 把0看作极小值 求最大子矩阵即可 
 1 #include <cstdio>
 2 #include <cctype>
 3 #include <iostream>
 4 
 5 typedef long long LL;
 6 
 7 const int INF=1000000;
 8 const int MAXN=510;
 9 
10 int n,m;
11 
12 int a[MAXN][MAXN];
13 
14 LL ans;
15 
16 inline void read(int&x) {
17     int f=1;register char c=getchar();
18     for(x=0;!isdigit(c);c=='-'&&(f=-1),c=getchar());
19     for(;isdigit(c);x=x*10+c-48,c=getchar());
20     x=x*f;
21 }
22 
23 
24 int hh() {
25     read(n);read(m);
26     for(int i=1;i<=n;++i) 
27       for(int j=1;j<=m;++j) {
28           read(a[i][j]);
29           if(!a[i][j]) a[i][j]=-INF;
30           a[i][j]+=a[i-1][j];
31       }
32     for(int i=0;i<=n;++i)
33       for(int j=i+1;j<=n;++j) {
34           LL tot=0;
35           for(int k=1;k<=m;++k) {
36               if(tot<0) tot=a[j][k]-a[i][k];
37               else tot+=a[j][k]-a[i][k];
38               ans=tot>ans?tot:ans;
39         }
40       }
41     std::cout<<ans;
42     return 0;
43 }
44 
45 int sb=hh();
46 int main(int argc,char**argv) {;}
代码

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值