題意:簡單的說就是求最大的面積,F表示可取,R表示不可取
思路:跟1506的思路是一樣的,就是變成了二維的了
#include#include #include #include using namespace std; const int MAXN = 1005; int l[MAXN],r[MAXN]; int a[MAXN]; int n,m,ans; int main(){ int t; scanf("%d",&t); while (t--){ ans = 0; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); a[0] = a[m+1] = -1; char str[10]; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ scanf("%s",str); if (str[0] == 'F') a[j]++; else a[j] = 0; } for (int j = 1; j <= m; j++) l[j] = r[j] = j; for (int j = 1; j <= m; j++) while (l[j] > 1 && a[l[j]-1] >= a[j]) l[j] = l[l[j]-1]; for (int j = m; j >= 1; j--) while (r[j] < m && a[r[j]+1] >= a[j]) r[j] = r[r[j]+1]; for (int j = 1; j <= m; j++) ans = max(ans,a[j]*(r[j]-l[j]+1)); } printf("%d\n",ans*3); } return 0; }