HDU - 1505 City Game(dp)

题意:求由R和F组成的矩阵中,最大的由F组成的矩阵面积。

分析:

1、hdu1506http://www.cnblogs.com/tyty-Somnuspoppy/p/7341431.html与此题相似。

2、将矩阵的每行看成1506中的坐标轴分别处理。

3、算出以该行为坐标轴,坐标轴上,每个由F组成的矩形的高度,与1506的区别是,1506中每个矩形高度已知。

4、按照1506的方法分别算出每个矩形最左边和最右边连续比其高的矩形的下标,通过(r[i][j] - l[i][j] + 1) * h[i][j]比较即可。

5、h[i][j]就相当于1506中a[i]。

h[i][j]----以第i行为坐标轴,第j个矩形的高度。

a[i]-----在坐标轴上,第i个矩形的高度。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int h[MAXN][MAXN], l[MAXN][MAXN], r[MAXN][MAXN];
int main(){
    int K;
    scanf("%d", &K);
    while(K--){
        memset(h, 0, sizeof h);
        memset(l, 0, sizeof l);
        memset(r, 0, sizeof r);
        int m, n;
        char c[5];
        scanf("%d%d", &m, &n);
        for(int i = 1; i <= m; ++i){
            for(int j = 1; j <= n; ++j){
                scanf("%s", c);
                if(c[0] == 'F') h[i][j] = h[i - 1][j] + 1;
                else h[i][j] = 0;
            }
        }

        int ans = 0;
        for(int i = 1; i <= m; ++i){
            l[i][1] = 1;
            for(int j = 2; j <= n; ++j){
                int tmp = j;
                while(tmp > 1 && h[i][tmp - 1] >= h[i][j]) tmp = l[i][tmp - 1];
                l[i][j] = tmp;
            }
            r[i][n] = n;
            for(int j = n - 1; j >= 1; --j){
                int tmp = j;
                while(tmp < n && h[i][tmp + 1] >= h[i][j]) tmp = r[i][tmp + 1];
                r[i][j] = tmp;
            }
            for(int j = 1; j <= n; ++j){
                ans = max(ans, (r[i][j] - l[i][j] + 1) * h[i][j]);
            }
        }
        printf("%d\n", ans * 3);
    }
    return 0;
}

  

posted @ 2017-08-10 22:20  Somnuspoppy  阅读(185)  评论(0编辑  收藏  举报