B. Maximum Submatrix 2----dp
来源:互联网 发布:雅马哈ts软件 编辑:程序博客网 时间:2024/06/06 09:21
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix ais a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j)(d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
1 11
1
2 21011
2
4 3100011000101
2
题目链接:http://codeforces.com/contest/375/problem/B
这个题本以为是暴力或者是利用某些奇技淫巧的很优雅的暴力,但是没有想到是个dp。。
真的好难想到这个题是dp,看了卿学姐的博客
http://www.cnblogs.com/qscqesze/p/4607185.html
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define LL long longusing namespace std;char s[5555][5555];int dp[5555][5555];bool cmp(int a,int b){ return a>b;}int main(){ int n,m; scanf("%d%d",&n,&m); int ans=0; for(int i=1;i<=n;i++){ scanf("%s",s[i]+1); } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(s[i][j]=='1'){ dp[j][i]=dp[j-1][i]+1; } } } for(int i=1;i<=m;i++){ sort(dp[i]+1,dp[i]+1+n,cmp); for(int j=1;j<=n;j++){ if(dp[i][j]==0){ break; } ans=max(dp[i][j]*j,ans); } } cout<<ans<<endl;}
- B. Maximum Submatrix 2----dp
- dp cf B. Maximum Submatrix 2
- cf dp B. Maximum Submatrix 2
- codeforces 375B B. Maximum Submatrix 2(dp)
- CodeForces 375B Maximum Submatrix 2
- CodeForces 375 B. Maximum Submatrix 2
- CodeForce 375B D - Maximum Submatrix 2
- CF:375B - Maximum Submatrix 2 不太像DP(sort的升序快速方法)
- Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序
- CodeForces 375B Maximum Submatrix 2(思维)
- Maximum Submatrix 2
- Maximum Submatrix
- Codeforces Round #221 (Div. 2) B. I.O.U. C. Divisible by Seven D. Maximum Submatrix 2 解题报告
- Maximum Submatrix & Largest Rectangle
- SCU 2096 Maximum Submatrix
- Codeforces Round #221 (Div. 2)-D. Maximum Submatrix 2
- CF 376D. Maximum Submatrix 2 枚举+前缀和
- 【DP】HDU2870 Largest Submatrix
- 模拟信号采样与AD转换
- jdbctemplate查询语句
- HDU 3068 最长回文 【manacher模版】
- 控件偏移问题
- 人工智能之机器学习算法体系汇总
- B. Maximum Submatrix 2----dp
- oracle rac 客户端taf测试
- Maven本地资源库
- 实现堆结构
- ndoejs+mongodb 开发4: 随机查询一条数据
- 多年iOS开发经验总结2
- jfinal page sql 查询
- iOS 把图片裁剪成圆形
- 关于animation简写各参数说明