给你一个01矩阵,求其中最大的01交替的矩阵
由于n最大才100,所以直接暴力乱搞
先求出第i行,所有列往上的合法长度,然后枚举以第j列为最左边的列,计算可以得到的最大矩阵
/*************************************************************************
> File Name: 2.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年05月07日 星期四 15时07分58秒
************************************************************************/
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
int ok[110][110];
class TheMatrix {
public:
int MaxArea(vector <string> mat) {
memset(ok, 0, sizeof(ok));
int n = mat.size();
int m = mat[0].length();
for (int i = 0; i < m; ++i) {
ok[i][0] = 1;
for (int j = 1; j < n; ++j) {
if (mat[j][i] == mat[j - 1][i]) {
ok[i][j] = 1;
}
else {
ok[i][j] = ok[i][j - 1] + 1; //the ith row of jth col
}
}
}
int size = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int mins = ok[j][i];
size = max(size, mins);
int flag = mat[i][j] - ‘0‘;
for (int k = j + 1; k < m; ++k) {
if (flag == mat[i][k] - ‘0‘) {
break;
}
flag ^= 1;
mins = min(mins, ok[k][i]);
size = max(size, (k - j + 1) * mins);
}
}
}
return size;
}
};
topcoder-srm610-div2-550(暴力乱搞)
原文地址:http://blog.csdn.net/guard_mine/article/details/45647709