hdu 2830 Matrix Swapping II
2016-08-19 12:54
411 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2830
题目描述:
Description
Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this matrix’s goodness.
We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
Input
There are several test cases in the input. The first line of each test case contains two integers N and M (1 ≤ N,M ≤ 1000). Then N lines follow, each contains M numbers (0 or 1), indicating the N * M matrix
Output
Output one line for each test case, indicating the maximum possible goodness.
Sample Input
Sample Output
题目大意:
给你一个n行m列的01矩阵,任何两列在任何时候都可以相互交换,叫你找出其中最大全1矩阵的面积
题目分析:
整体思想跟求一维的最大矩阵面积相同,这里的n行我们可以分n次来求,每次求以第i行为底的最大全1矩阵的面积,注意由于每一列都可以任意换位置,所以我们只要找到比他高的个数就可以了,在这里,我们可以先排一下序,从低到高,那么每个小矩阵所代表的面积就很显然的看出来了,是v[j]*(m-j+1),不理解的话可以自己手画一个图,从低到高画一些矩阵,就可以看出来了。还要注意的地方就是我们要新开一个数组专门进行排序,因为如果直接拿原来的数组进行排序的话那么他下面的值就会发生改变,就不符合整列之间进行交换的要求了。
AC代码:
题目描述:
Description
Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this matrix’s goodness.
We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
Input
There are several test cases in the input. The first line of each test case contains two integers N and M (1 ≤ N,M ≤ 1000). Then N lines follow, each contains M numbers (0 or 1), indicating the N * M matrix
Output
Output one line for each test case, indicating the maximum possible goodness.
Sample Input
3 4 1011 1001 0001 3 4 1010 1001 0001
Sample Output
4 2 Note: Huge Input, scanf() is recommended.
题目大意:
给你一个n行m列的01矩阵,任何两列在任何时候都可以相互交换,叫你找出其中最大全1矩阵的面积
题目分析:
整体思想跟求一维的最大矩阵面积相同,这里的n行我们可以分n次来求,每次求以第i行为底的最大全1矩阵的面积,注意由于每一列都可以任意换位置,所以我们只要找到比他高的个数就可以了,在这里,我们可以先排一下序,从低到高,那么每个小矩阵所代表的面积就很显然的看出来了,是v[j]*(m-j+1),不理解的话可以自己手画一个图,从低到高画一些矩阵,就可以看出来了。还要注意的地方就是我们要新开一个数组专门进行排序,因为如果直接拿原来的数组进行排序的话那么他下面的值就会发生改变,就不符合整列之间进行交换的要求了。
AC代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int v[1005]; int map[1005][1005]; int n,m,tmp,Max; int main() { while(scanf("%d%d",&n,&m)!=EOF) { memset(map,0,sizeof(map)); Max=-0xfffffff; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%1d",&map[i][j]); if(map[i][j]) map[i][j]+=map[i-1][j]; v[j]=map[i][j]; } sort(v+1,v+m+1); for(int j=1;j<=m;j++) Max=max(Max,v[j]*(m-j+1)); } cout<<Max<<endl; } return 0; }
相关文章推荐
- HDU-2830-Matrix Swapping II(DP)
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II(最大子矩阵续)
- HDU 2830 Matrix Swapping II(最大完全子矩阵之可移动列)
- TOJ 3667 HDU 2830 Matrix Swapping II
- hdu - 2830 - Matrix Swapping II(排序)
- HDU 2830 Matrix Swapping II (DP,最大全1矩阵)
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II (dp+树状数组)
- HDu 2830 Matrix Swapping II(dp)
- HDU 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II *
- HDU 2830 Matrix Swapping II (最大列可移动子矩形面积)
- HDU 2830 Matrix Swapping II(最大完全子矩阵之可移动列)
- HDU 2830 Matrix Swapping II(最大完全子矩阵之可移动列)
- HDU 2830 Matrix Swapping II (DP,最大全1矩阵)
- HDU 2830 Matrix Swapping II (最大完全子矩阵之可移动列)
- HDu 2830 Matrix Swapping II(dp)