51nod1158 全是1的最大子矩阵
跟最大子矩阵差不多O(n3)扫一下。有更优写法?挖坑!
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=505;
int a[nmax][nmax];
void maxs(int &a,int b){
if(a<b) a=b;
}
int main(){
int m=read(),n=read();
rep(i,1,n) rep(j,1,m) a[i][j]=read(),a[i][j]+=a[i-1][j];
int ans=0,cnt;
rep(i,1,n) rep(j,i,n) {
cnt=0;
rep(k,1,m){
if(a[j][k]-a[i-1][k]!=j-i+1) maxs(ans,cnt*(j-i+1)),cnt=0;
else cnt++;
}
maxs(ans,cnt*(j-i+1));
}
printf("%d\n",ans);
return 0;
}
第1行:2个数m,n中间用空格分隔(2 <= m,n <= 500)
第2 - N + 1行:每行m个数,中间用空格分隔,均为0或1。
输出最大全是1的子矩阵的面积。
3 3
1 1 0
1 1 1
0 1 1
4
51nod1158 全是1的最大子矩阵的更多相关文章
- 51nod 1158 全是1的最大子矩阵
题目链接:51nod 1158 全是1的最大子矩阵 题目分类是单调栈,我这里直接用与解最大子矩阵类似的办法水过了... #include<cstdio> #include<cstri ...
- 51Nod 1158 全是1的最大子矩阵 —— 预处理 + 暴力枚举 or 单调栈
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1158 1158 全是1的最大子矩阵 基准时间限制:1 秒 空 ...
- HDU -1506 Largest Rectangle in a Histogram&&51nod 1158 全是1的最大子矩阵 (单调栈)
单调栈和队列讲解:传送门 HDU -1506题意: 就是给你一些矩形的高度,让你统计由这些矩形构成的那个矩形面积最大 如上图所示,如果题目给出的全部是递增的,那么就可以用贪心来解决 从左向右依次让每一 ...
- 51nod 1158 全是1的最大子矩阵(单调栈 ,o(n*m))
前置问题:51nod 1102 面积最大的矩形 附上链接: 51nod 1102 面积最大的矩形 这题的题解博客 需要了解的知识:单调栈,在前置问题中已经讲解. 解题思路 对每行求左边连续1的个数,得 ...
- leetcode-165周赛-1277-统计全为1的正方形子矩阵
题目描述: 自己的提交: class Solution: def countSquares(self, matrix: List[List[int]]) -> int: if not matri ...
- PHP算法之统计全为 1 的正方形子矩阵
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积. 示例: 输入: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0 输出: 4 来源:力扣( ...
- UVA-10074 最大子矩阵 DP
求出大矩阵里面全为0的最大子矩阵 我自己用的个挫DP写的,感觉写的不是很好,其实可以再优化,DP想法就是以 0 0 到当前 i j 为整体矩阵考虑,当前 i j就是从 i-1 j或者 i,j-1那里最 ...
- codevs 2491 玉蟾宫
codevs 2491 玉蟾宫 http://codevs.cn/problem/2491/ 题目描述 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉 ...
- bzoj1127[POI2008]KUP 悬线法
Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 485 Solved: 174[Submit][Status][D ...
随机推荐
- linux 全自动提权 exp perl脚本
linux 全自动提权 exp perl脚本 作者: admin 日期: 2013/01/19发表评论 (0) 查看评论 国外流传过来的 地址 http://dl.packetstormsecur ...
- java 以及 vs 的快捷键
javactrl+shift+y 小写ctrl+shift+x 大写ctrl+shift+f 格式化代码 vsctrl+u 小写ctrl+shift+u 大写ctrl+k+f 格式化代码
- Project Euler 106:Special subset sums: meta-testing 特殊的子集和:元检验
Special subset sums: meta-testing Let S(A) represent the sum of elements in set A of size n. We shal ...
- 国内银行CNAPS CODE 查询 苹果开发者,应用内购,需要填写税务相关信息必须的
https://e.czbank.com/CORPORBANK/QYUK http://weekend.blog.163.com/blog/static/746895820127961346724/
- 转:Move all SQL Server system databases at one time
Problem One task that you may need to do as a DBA is to move the system databases from one location ...
- Java:IO流之转换流
IO流的基本流情况: 字符流: 字符流缓冲区: FileReader BufferedReader FileWriter ...
- Java:字符串缓冲区StringBuffer和StringBuilder的使用
StringBuffer特点: 1.是字符缓冲区,一个容器(不论缓冲区内容怎么变化,StringBuffer这个容器对象都不会改变) 2.是可变长度的 3.可以直接操作多个数据类型 4.最终会通过to ...
- ActionResult
ActionResult public abstract class ActionResult { public abstract void ExecuteResult(ControllerConte ...
- BI
http://www.cnblogs.com/biwork/p/3276455.html http://www.cnblogs.com/biwork/p/3328879.html http://www ...
- warning:deprecated conversion from string constant to 'char *' 解决方案
#include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } i ...