[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 ...
随机推荐
- Matlab实现单变量线性回归
一.理论 二.数据集 6.1101,17.592 5.5277,9.1302 8.5186,13.662 7.0032,11.854 5.8598,6.8233 8.3829,11.886 7.476 ...
- 监听HTML input输入框值的即时变化onpropertychange、oninput兼容IE,Chrome,FF,Opera等
转自:http://blog.csdn.net/itchiang/article/details/7769337 要达到的效果 很多情况下我们都会即时监听输入框值的变化,以便作出即时动作去引导浏览者增 ...
- windows 7 下快速搭建php环境 windows7+IIS7+php
1. 安装IIS v7.0 控制面板-程序和功能-打开或关闭Windows 功能 测试是否成功安装IIS v7.0,在浏览器输入:http://localhost/ 或者http://12 ...
- sprytabbedpanels.js库之在页面中插入Tabbed Panels
向页面加入sprytabbedpanels.js文件.<script src="SpryAssets/SpryTabbedPanels.js" type="text ...
- Spring声明式事务配置管理方法(转)
项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加方法: 点击项目右键->Build Path->Add libra ...
- Hello world,Hello 2015,Bye 2014
序 在我写下“在”这个字的时候已经是2014-12-31 19:59,14年最后一天了,总觉得不写点东西祭奠一下那些被自己虐死的脑细胞,心里就不舒服. 那就从生活,工作,学习三个方面,总结一下吧. 生 ...
- login shell 和 non-login shell 的区别
介绍之前先思考一个问题:有时我们通过su命令切换用户后,却发现并没有进入该用户的shell环境.这是为什么? login shell:取得bash时需要完整的登录流程.就是说通过输入账号和密码登录系统 ...
- Javascript 图片延迟加载之理论基础
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 【uva1502/hdu4117-GRE Words】DP+线段树优化+AC自动机
这题我的代码在hdu上AC,在uva上WA. 题意:按顺序输入n个串以及它的权值di,要求在其中选取一些串,前一个必须是后一个的子串.问d值的和最大是多少. (1≤n≤2×10^4 ,串的总长度< ...
- 欧拉工程第53题:Combinatoric selections
package projecteuler51to60; class p53{ void solve1(){ int count=0; int Max=1000000; int[][] table=ne ...