题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 310;
int n, m, k;
int a[N][N];
int minv[N][N], maxv[N][N];
int main()
{
int T;
cin >> T;
for (int cases = 1; cases <= T; cases ++)
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
{
cin >> a[i][j];
minv[i][j] = maxv[i][j] = a[i][j];
}
int res = n;
for (int len = 2; len <= m; len ++)//宽度
for (int i = 1; i + len - 1 <= m; i ++)//每一行左端点
for (int j = 1, s = 0; j <= n; j ++)//枚举每一行
{
int &mn = minv[j][i], &mx = maxv[j][i];
mn = min(mn, a[j][i + len - 1]);
mx = max(mx, a[j][i + len - 1]);
if (mx - mn <= k)
{
s ++;
res = max(res, s * len);
}
else s = 0;
}
printf("Case #%d: %d\n", cases, res);
}
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla