[HDOJ2830]Matrix Swapping II(胡搞)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2830
给一个矩阵只有0和1,矩阵的列可以和其他列交换无数次,问交换后整个矩阵形成的最大的全是1的子矩阵的面积。
思路:可以每次枚举当前行的每一列的连续为1的个数。然后从大到小排序,每次更新当前最大的面积。(排完序以后可以看成某经典单调队列题,面积就是下标*当前高度)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = (a); i < (n); i++)
#define Cls(a) memset((a), 0, sizeof(a))
const int maxn = ; int n, m;
int h[maxn];
int dp[maxn];
char G[maxn][maxn]; int main() {
FRead();
while(~Rint(n) && ~Rint(m)) {
int ans = ;
Cls(h); Cls(dp);
Rep(i, n) Rs(G[i]);
Rep(i, n) {
Rep(j, m) {
if(G[i][j] == '') h[j]++;
else h[j] = ;
dp[j] = h[j];
}
sort(dp, dp+m, greater<int>());
Rep(j, m) {
if(dp[j] == ) break;
ans = max(ans, dp[j] * (j + ));
}
}
printf("%d\n", ans);
}
return ;
}
[HDOJ2830]Matrix Swapping II(胡搞)的更多相关文章
- 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)
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 ...
- HDU 2830 Matrix Swapping II
给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...
- 【HDOJ】2830 Matrix Swapping II
简单DP. /* 2830 */ #include <iostream> #include <string> #include <map> #include < ...
- 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列格 ...
- [LeetCode]Integer Break(Dp或胡搞或推公式)
343. Integer Break Given a positive integer n, break it into the sum of at least two positive intege ...
- HDU 4690 EBCDIC (2013多校 1005题 胡搞题)
EBCDIC Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Su ...
随机推荐
- 好用到没朋友的大数模板(c++) 2014-10-01 15:06 116人阅读 评论(0) 收藏
#include <iostream> #include <cstring> using namespace std; #define DIGIT 4 //四位隔开,即万进制 ...
- Css选择器的优先级
a = 行内样式style. b = ID选择器的数量. c = 类.伪类和属性选择器的数量. d = 类型选择器和伪元素选择器的数量. 选择器 等级(a,b,c,d) style=”” 1,0,0, ...
- Tomcat自动启动脚本
Tomcat自动启动脚本#!/bin/bash # chkconfig: 2345 10 90 # description: Starts and Stops the Tomcat daemon. T ...
- css两个form不换行,两个div并排代码
1.form不换行通过table布局实现 <table> <tr> <td> <form method="get" action=&quo ...
- vi/vim使用指北 ---- Learning the vi and Vim Editors 读书 笔记
vi/vim作为liux系统下最强大,最流行的文本编辑器之一.边看<Learning the vi and vim Editor>边学习vim,顺便做写简单的笔记,供以后查询. 没看这本书 ...
- HDU 4148 Length of S(n)(字符串)
题目 字符串处理 题意要猜,解析见代码: /* 这题每个S(n)是描述S(n-1)值 例如: S(1)=1; S(2)=11;即描述S(1)有1个1=11 S(3)=21;即描述S(2)有2个1=21 ...
- 更改cmd代码页,修正语言显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 rem 英文 chcp 437 rem 日文 chcp 932 rem 简体中文 chcp 936 re ...
- linux中的磁盘的MBR记录详解
在硬盘中,硬盘的0柱面0磁头第一个1扇区称为主引导扇区,也叫主引导记录-MBR(main boot record),其中MBR是以下三个部分组成 1.Bootloader,主引导程序---446个字节 ...
- Android 基于Socket的聊天应用(二)
很久没写BLOG了,之前在写Android聊天室的时候答应过要写一个客户(好友)之间的聊天demo,Android 基于Socket的聊天室已经实现了通过Socket广播形式的通信功能. 以下是我写的 ...
- linux 如何让程序后台执行
$ (./test.sh &) $ setsid ./test.sh & $ nohup ./test.sh & 具体的转自:http://digdeeply.or ...