zoukankan      html  css  js  c++  java
  • uva1330 在一个大的矩阵中寻找面积最大的子矩阵

    大白书 P50页

    #include <algorithm>
    #include <cstdio>
    using namespace std;
    const int maxn=1005;
    int ma[maxn][maxn];
    int Left[maxn][maxn],Right[maxn][maxn],up[maxn][maxn];
    int main()
    {
         int cas;
         scanf("%d",&cas);
          while(cas--){
              int n,m;
              scanf("%d%d",&n,&m);
              for(int i=0; i<n; i++)
                 for(int j=0; j<m; j++){
                      char ch =getchar();
                       while( ch != 'F' && ch != 'R' )ch=getchar();
                       ma[i][j]= ch == 'F' ? 0 : 1 ;
                 }
    
              int ans=0;
              for(int i=0; i<n; i++){
                 int lo=-1,ro=m;
                 for(int j=0; j<m; j++)
                 if(ma[i][j]==1){
                    Left[i][j]=up[i][j]=0; lo=j;
                 }else{
                     up[i][j]=i==0?1:up[i-1][j]+1;
                   Left[i][j] = i == 0 ?lo+1:max( lo+1, Left[i-1][j] );
    
                 }
                 for(int j=m-1; j>=0; j--)
                 if(ma[i][j]==1){
                    Right[i][j]=m;ro=j;
                 }else{
                   Right[i][j]=i==0?ro-1:min(ro-1,Right[i-1][j]);
                   ans=max(ans,up[i][j]*(Right[i][j]-Left[i][j]+1));
                 }
    
              }
              printf("%d
    ",ans*3);
          }
        return 0;
    }
    View Code
  • 相关阅读:
    ReactJs入门
    Studio-Class Diagram
    Visual Studio-Sequence Diagram
    架构、职责、数据一致性
    Microsoft Build 2015
    Net下无敌的ORM
    SpringMVC1
    插件式Web框架
    ASP.NET的CMS
    Android Drawable绘图学习笔记(转)
  • 原文地址:https://www.cnblogs.com/Opaser/p/4432061.html
Copyright © 2011-2022 走看看