HDU 2830 Matrix Swapping II (最大子矩阵)
来源:互联网 发布:如何做数据统计 编辑:程序博客网 时间:2024/05/22 14:13
Matrix Swapping II
Time Limit: 9000/3000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 809 Accepted Submission(s): 547
Problem 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
1 /* 2 这道题跟1505,1506,2870又是类似的。求最大矩阵。 3 不同的是,这里的每一列都是可以移动的,所以不必找左右边界的问题,对于 4 每一层,统计这一层中每一列的高度,然后将这些高度按降序排序,就解决了 5 列可以移动的问题,最后答案ans = max(ans,num[i]*i); 6 7 328MS 5168K 8 */ 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 #include <algorithm> 13 #define SIZE 1005 14 15 using namespace std; 16 17 char ch[SIZE][SIZE]; 18 int height[SIZE][SIZE]; 19 int num[SIZE]; 20 int n,m; 21 22 bool cmp(int a,int b) 23 { 24 return a > b; 25 } 26 27 int main() 28 { 29 while(~scanf("%d%d",&n,&m)) 30 { 31 int ans = 0; 32 for(int i=1; i<=n; i++) 33 { 34 scanf("%s",ch[i]+1); 35 } 36 for(int i=1; i<=n; i++) 37 { 38 for(int j=1; j<=m; j++) 39 { 40 if(ch[i][j] == '1') 41 height[i][j] = height[i-1][j]+1; 42 else 43 height[i][j] = 0; 44 num[j] = height[i][j]; 45 } 46 sort(num+1,num+1+m,cmp); 47 for(int i=1; i<=m; i++) 48 ans = max(ans,num[i]*i); 49 } 50 printf("%d\n",ans); 51 } 52 return 0; 53 } 54 /* 55 网上看到的空间优化,而且代码更简洁,值得学习,按照这个思路,再打了一遍。 56 57 312MS 240K 58 59 #include <iostream> 60 #include <cstdio> 61 #include <cstring> 62 #include <algorithm> 63 #define SIZE 1005 64 65 using namespace std; 66 67 char ch[SIZE]; 68 int height[SIZE]; 69 int num[SIZE]; 70 int n,m; 71 72 bool cmp(int a,int b) 73 { 74 return a > b; 75 } 76 77 int main() 78 { 79 while(~scanf("%d%d",&n,&m)) 80 { 81 memset(height,0,sizeof(height)); 82 int ans = 0; 83 for(int i=1; i<=n; i++) 84 { 85 scanf("%s",ch+1); 86 for(int j=1; j<=m; j++) 87 { 88 if(ch[j] == '1') 89 height[j] ++; 90 else 91 height[j] = 0; 92 num[j] = height[j]; 93 } 94 sort(num+1,num+1+m,cmp); 95 for(int i=1; i<=m; i++) 96 ans = max(ans,num[i]*i); 97 } 98 printf("%d\n",ans); 99 }100 return 0;101 }102 */
- HDU 2830 Matrix Swapping II (最大子矩阵)
- HDU 2830 Matrix Swapping II(dp最大子矩阵和)
- 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 (DP,最大全1矩阵)
- HDU 2830 Matrix Swapping II (最大列可移动子矩形面积)
- hdoj 2830 Matrix Swapping II (DP求最大子矩阵的变型题)
- HDu 2830 Matrix Swapping II(dp)
- hdu - 2830 - Matrix Swapping II(排序)
- 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
- 对 LCS 和 LIS 的总结
- HDU 1506 Largest Rectangle in a Histogram
- HDU 1505 City Game
- RPi变成一个DHCP服务器
- SHGetFileInfo函数
- HDU 2830 Matrix Swapping II (最大子矩阵)
- HDU 2870 Largest Submatrix (最大子矩阵)
- MS SqlServer 性能优化
- HDU 2571 命运 (简单DP)
- HDU 1069 Monkey and Banana (最长上升子序列)
- HDU 1421 搬寝室
- HDU 1058 & POJ 2247 Humble Number
- HDU 1978 How many ways
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)