Matrix Swapping II(求矩阵最大面积,dp)
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
We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
1011
1001
0001
3 4
1010
1001
0001
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)的更多相关文章
- HDU 2830 Matrix Swapping II (预处理的线性dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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 ...
- [HDOJ2830]Matrix Swapping II(胡搞)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2830 给一个矩阵只有0和1,矩阵的列可以和其他列交换无数次,问交换后整个矩阵形成的最大的全是1的子矩阵 ...
- HDU 2830 Matrix Swapping II
给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...
- HDU 2830:Matrix Swapping II(思维)
http://acm.hdu.edu.cn/showproblem.php?pid=2830 题意:-- 思路:对于每一列,它是固定的,用dp[][]处理出连续的长度.例如: 假设我们扫第四列的时候, ...
- hdu 2830 Matrix Swapping II(额,,排序?)
题意: N*M的矩阵,每个格中不是0就是1. 可以任意交换某两列.最后得到一个新矩阵. 问可以得到的最大的子矩形面积是多少(这个子矩形必须全是1). 思路: 先统计,a[i][j]记录从第i行第j列格 ...
- 【HDOJ】2830 Matrix Swapping II
简单DP. /* 2830 */ #include <iostream> #include <string> #include <map> #include < ...
- POJ 1151 Atlantis(经典的线段树扫描线,求矩阵面积并)
求矩阵的面积并 采用的是区间更新 #include <iostream> #include <stdio.h> #include <string.h> #inclu ...
- HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)
做这道题之前,建议先做POJ 1151 Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...
随机推荐
- Swift笔记2
1.元组类型 let cat =(age:4,weight:2,cocle:"black",beauty :true) if(cat.beauty){ printf("我 ...
- 为程序指定运行时所在的CPU核
internal class Program { [DllImport("kernel32.dll")] private static extern uint GetTickCou ...
- 转载: Nova-Router 分析
很早的实现了,nova代码已经做了很多修改了. 以创建实例 URL(http://10.191.7.32:8773/v1.1/service?*****)为例说明 Router 的执行流程 1. 依据 ...
- MySQL必知必会 学习笔记(一)
第一章 了解SQL 模式: 关于数据库和表的布局以及特性的信息.[描述表可以存储什么样的数据,数据如何分解,各部分信息如何命名等等,可以用来描述数据库中特定的表以及整个数据库(和其中表的关系)] ...
- 利用margin代替小图标的绝对定位;使代码更简洁
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- <select>标签后循环加入选项<option>——jquery
if (data.ReplaceDataFields != null) { $.each(data.ReplaceDataFields, function (i, item) { ...
- vpn pptp配置
安装 yum install pptpd 配置pptpd 改动/etc/pptpd.conf设置 localip 192.168.20.1 remoteip 192.168.20.234-238,19 ...
- where can I find source of com.android.internal.R.styleable.AlertDialog_multiChoiceItemLayout?
I want to modify Alert dialog multi select layout. For my program I want two line multi-select item. ...
- 微软将Bing变开放平台 同谷歌争夺开发者
微软在编译者大会上宣布将Bing作为平台开放,此举显然旨在改变谷歌(微博)一家独大的局面. 报道称,微软知道如何创建平台.因此当它发布新平台时,都值得业界仔细关注.就在上周之前,微软Bing给大家的印 ...
- VM 443端口冲突解决办法
netstat -aon|findstr "443" 找到占用443的进程号: tasklist|findstr "2016" 根据进程号2016找到占用443 ...