博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序
阅读量:6325 次
发布时间:2019-06-22

本文共 2611 字,大约阅读时间需要 8 分钟。

B. Maximum Submatrix 2

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/375/B

Description

You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

Output

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

Sample Input

1 1

1

Sample Output

1

HINT

 

题意

给你一个01矩阵,行与行之间可以交换位置

然后问你构成构成最大的只含1的矩形的面积是多少

题解:

我们分析一下,首先我们预处理一下

dp[i][j]表示第i列第j行往左边最远能延长多远

因为列是不会变的,所以我们对于每一列都排序,然后利用dp的思想往下找

到dp[i][j]==0的时候break,因为显然剩下的都是0了

代码

 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define test freopen("test.txt","r",stdin)#define maxn 5005#define mod 10007#define eps 1e-5const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//**************************************************************************************char s[maxn][maxn];int dp[maxn][maxn];bool cmp(int a,int b){ return a>b;}int main(){ int n=read(),m=read(); int ans=0; for(int i=1;i<=n;i++) scanf("%s",s[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]=='1') dp[j][i]=dp[j-1][i]+1; for(int i=1;i<=m;i++) { sort(dp[i]+1,dp[i]+1+n,cmp); for(int j=1;j<=n;j++) { if(dp[i][j]==0) break; ans=max(dp[i][j]*j,ans); } } cout<
<

 

转载地址:http://zjmaa.baihongyu.com/

你可能感兴趣的文章
java异常 之 异常的层次结构
查看>>
数据库设计原则
查看>>
T - stl 的mapⅡ
查看>>
Matlab中的取整-floor,ceil,fix,round
查看>>
Atitit .c#的未来新特性计划草案
查看>>
经验总结17--submitbutton,ajax提交
查看>>
mysql分表技术
查看>>
.Net 垃圾回收和大对象处理 内存碎片整理
查看>>
Linux是如何启动的
查看>>
HiKey连接
查看>>
wget 参数大全
查看>>
使用Loadrunner进行文件的上传和下载
查看>>
Linux C 静态库(.a) 与 动态库(.so) 的详解
查看>>
JS函数
查看>>
sql语句分组/排序/计算总数/连接等sql语句书写
查看>>
【.net 深呼吸】启动一个进程并实时获取状态信息
查看>>
MVC5 的MicrosoftOwinSecurity扩展插件——微信,QQ登录第三方源码
查看>>
分布式系统理论基础 - CAP
查看>>
mysql 用户管理和权限设置
查看>>
【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目
查看>>