[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 ...
随机推荐
- 【BZOJ】【3850】ZCC Loves Codefires
贪心 就跟NOIP2012国王游戏差不多,考虑交换相邻两题的位置,对其他题是毫无影响的,然后看两题顺序先后哪个更优.sort即可. WA了一次的原因:虽然ans开的是long long,但是在这一句: ...
- smaa github iryoku
dx10 demo 这东西我没法跑nsight ...这就坑大了 里面有个 RenderTargetCollection这个东西里面有很多 rendertargets 最让我苦恼的就是 sceneRT ...
- poi生成excel
转自:http://www.cnblogs.com/bmbm/archive/2011/12/08/2342261.html 1.首先下载poi-3.6-20091214.jar,下载地址如下: ht ...
- HDU1070Milk
Milk Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description ...
- ASP.NET 大文件上传的简单处理
在 ASP.NET 开发的过程中,文件上传往往使用自带的 FileUpload 控件,可是用过的人都知道,这个控件的局限性十分大,最大的问题就在于上传大文件时让开发者尤为的头疼,而且,上传时无法方便的 ...
- Sqli-labs less 23
第二部分/page-2 Advanced injection Less-23 Sql语句为$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1 ...
- POJ 3281
Dining Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8577 Accepted: 3991 Descriptio ...
- javascript的Function 和其 Arguments
http://shengren-wang.iteye.com/blog/1343256 javascript的Function属性:1.Arguments对象2.caller 对调用单前函数的Func ...
- CodeIgniter 常量ENVIRONMENT设置要注意的地方
http://bbs.phpchina.com/thread-274514-1-1.html index.php ,这是CodeIgniter的入口文件,做开发是,都会设置一下define('ENVI ...
- js 阻止冒泡 兼容性方法
function customstopPropagation(e){ var ev = e || window.event; if (ev.stopPropagation) { ev.stopProp ...