Matrix Swapping II

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1543    Accepted Submission(s): 1036

Problem Description
Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this matrix’s goodness. 
We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
 
Input
There are several test cases in the input. The first line of each test case contains two integers N and M (1 ≤ N,M ≤ 1000). Then N lines follow, each contains M numbers (0 or 1), indicating the N * M matrix
 
Output
Output one line for each test case, indicating the maximum possible goodness.
 
Sample Input
3 4
1011
1001
0001
3 4
1010
1001
0001
 
Sample Output
4
2

Note: Huge Input, scanf() is recommended.

 
题解:

也是求最大矩阵的,只不过可以相互交换任意两列。

访问每一行时,求出每个点的高度,然后排序,以该点为高时的宽度就很容易看出来,面积取最大的就可以了。

ans=max(ans,(k-j+1)*s[j]);由于可以交换列,这里随着往右走,宽度逐渐减小,找最大值;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x) scanf("%lf",&x)
#define P_ printf(" ")
typedef long long LL;
const int MAXN=;
char mp[MAXN][MAXN];
int dp[MAXN][MAXN];
int s[MAXN];
int main(){
int N,M;
while(~scanf("%d%d",&N,&M)){
mem(dp,);
int ans=;
for(int i=;i<=N;i++){
scanf("%s",mp[i]);
for(int j=M;j>=;j--){
mp[i][j]=mp[i][j-];
}
}
for(int i=;i<=N;i++){
int k=;
for(int j=;j<=M;j++){
if(mp[i][j]==''){
dp[i][j]=dp[i-][j]+;
s[++k]=dp[i][j];
}
}
sort(s+,s+k+);
for(int j=;j<=k;j++){
ans=max(ans,(k-j+)*s[j]);
}
}
printf("%d\n",ans);
}
return ;
}

Matrix Swapping II(求矩阵最大面积,dp)的更多相关文章

  1. HDU 2830 Matrix Swapping II (预处理的线性dp)

    Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. HDu 2830 Matrix Swapping II(dp)

    Problem Description Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangl ...

  3. [HDOJ2830]Matrix Swapping II(胡搞)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2830 给一个矩阵只有0和1,矩阵的列可以和其他列交换无数次,问交换后整个矩阵形成的最大的全是1的子矩阵 ...

  4. HDU 2830 Matrix Swapping II

    给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...

  5. HDU 2830:Matrix Swapping II(思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=2830 题意:-- 思路:对于每一列,它是固定的,用dp[][]处理出连续的长度.例如: 假设我们扫第四列的时候, ...

  6. hdu 2830 Matrix Swapping II(额,,排序?)

    题意: N*M的矩阵,每个格中不是0就是1. 可以任意交换某两列.最后得到一个新矩阵. 问可以得到的最大的子矩形面积是多少(这个子矩形必须全是1). 思路: 先统计,a[i][j]记录从第i行第j列格 ...

  7. 【HDOJ】2830 Matrix Swapping II

    简单DP. /* 2830 */ #include <iostream> #include <string> #include <map> #include < ...

  8. POJ 1151 Atlantis(经典的线段树扫描线,求矩阵面积并)

    求矩阵的面积并 采用的是区间更新 #include <iostream> #include <stdio.h> #include <string.h> #inclu ...

  9. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

随机推荐

  1. 使用SecureCRT网络连接树莓派

        为了更加方便可以通过网络来连接.控制树莓派,使用SecureCRT可以通过网络来连接树莓派.     1.在树莓派上通过终端命令ifconfig 来查看当前树莓派的IP地址:     IP地址 ...

  2. STM32与LPC系列ARM资源之比较

    由于有周立公开发板的影响,LPC系列的开发板在工程师心目中一般是入门的最好型号之一.这次刚好有STM32的竞赛,正好将两者的资源进行比较一下(LPC系列以LPC213X为例). LPC213X包括LP ...

  3. Keil 中的预处理命令const

    在keil中,宏定义是一个重要内容.无参数的宏作为常量,而带参数的宏则可以提供比函数更高的调用效率.但预处理只是进行简单的文本代替,而不做语法检查,所以会存在一些问题. 例如:#define BUFS ...

  4. HTTP的头部

    if($this->GetHead("http-edition")=="HTTP/1.1") $httpv = "HTTP/1.1"; ...

  5. IsNullOrEmpty和s == null || s.Length == 0哪个快

    在写扩展方法时,看到有人用==null这个方法,说快,上网找了些资料,最后在csdn的博客上看到了一篇文章,说实测是后两者快,于是我也试着做了一个程序运行了一下,却发现这样的结果: 我测试了一个,发现 ...

  6. SQL数据库知识二(Day 25)

    又到了总结知识的时候了,今天主要把SQL数据库给简单的学完了,明天开始就要开始学ADO.NET的知识了.好了,话不多说,还是看一下今天都学了哪些内容. 1  字符串类型的知识点 --类型的使用 --截 ...

  7. url的4种访问方式

    1.PATHINFO 模式 -- 重点!!!!!! http://域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值2 (可以修改 'URL_PATHINFO_DEPR'=>'-',/ ...

  8. SSH框架整合 日志处理Spring结合 log4j、slf4j

    1. 加入log4j和slf4j的jar包 2. web.xml: <context-param> <!--log4j配置地址 --> <param-name>lo ...

  9. VBA基础概念

    一:VBA对象 'VBA对象 'VBA中的对象其实就是我们操作的具有方法.属性的excel中支持的对象 'Excel中的几个常用对象表示方法 '1.工作簿 ' Workbooks 代表工作簿集合,所有 ...

  10. Java程序执行Linux命令

    Java程序中要执行linux命令主要依赖2个类:Process和Runtime 首先看一下Process类: ProcessBuilder.start() 和 Runtime.exec 方法创建一个 ...