HDU 2830 Matrix Swapping II
2014-07-29 22:52
351 查看
给一个矩阵,依然是求满足条件的最大子矩阵
不过题目中说任意两列可以交换,这是对题目的简化
求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始)
因为排序会影响到h数组下一行的求解,所以将h数组中的元素复制到temp数组中去,再排序
代码君
不过题目中说任意两列可以交换,这是对题目的简化
求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始)
因为排序会影响到h数组下一行的求解,所以将h数组中的元素复制到temp数组中去,再排序
//#define LOCAL #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1010; char map[maxn][maxn]; int h[maxn], temp[maxn]; int main(void) { #ifdef LOCAL freopen("2830in.txt", "r", stdin); #endif int row, col; while(scanf("%d%d", &row, &col) == 2) { int i, j; for(i = 0; i < row; ++i) scanf("%s", map[i]); memset(h, 0, sizeof(h)); int ans = 0; for(i = 0; i < row; ++i) { for(j = 0; j < col; ++j) { if(map[i][j] == '1') ++h[j]; else h[j] = 0; } memcpy(temp, h, sizeof(h)); sort(temp, temp + col); for(j = 0; j < col; ++j) ans = max(ans, (col-j)*temp[j]); } printf("%d\n", ans); } return 0; }
代码君
相关文章推荐
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II(hdu1505的加强版)
- 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(额,,排序?)
- Matrix Swapping II - HDU 2830 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 (预处理的线性dp)
- HDU 2830 Matrix Swapping II
- hdu 2830 Matrix Swapping II
- HDU 2830 Matrix Swapping II (预处理的线性dp)
- HDU-2830-Matrix Swapping II(DP)
- hdu 2830 Matrix Swapping II