Day3-T3
Describe:又是这种最大子矩阵捆绑一堆条件的题
code:
#pragma GCC optimize(2) #include<bits/stdc++.h> #define jxcjulao 1111 using namespace std; long long lft[jxcjulao][jxcjulao],up[jxcjulao][jxcjulao],a[jxcjulao][jxcjulao]; long long n,m,minn,ans,f,l; inline long long read(){ long long ret=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();} while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar(); return ret*f; } inline double read2(){ double X=0,Y=1.0;int w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch))X=X*10+(ch^48),ch=getchar(); ch=getchar(); while(isdigit(ch)) X+=(Y/=10)*(ch^48),ch=getchar(); return w?-X:X; } inline void write(int x){ if(x<0){putchar('-');write(-x);return;} if(x/10) write(x/10); putchar(x%10+'0'); } int main(){ // freopen("matrix.in","r",stdin); // freopen("matrix.out","w",stdout); n=read(),m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { up[i][j]=lft[i][j]=1; for(int k=i;k>1;k--) //向上至多延伸 if(a[k][j]>a[k-1][j])up[i][j]++; else break; for(int k=j;k>1;k--) //向左至多延伸 if(a[i][k]>a[i][k-1])lft[i][j]++; else break; } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=up[i][j];k>=1;k--) { if(k*lft[i][j]<ans)break; //剪枝 minn=lft[i][j]; //Lft至多到哪里 for(l=i;l>=i-k+1;l--) minn=min(minn,lft[l][j]); //(i,j)->(i+up[i][j],j)中最小的 lft[x][y] if(k*minn<ans)continue; //剪枝 for(l=j;l>=j-minn+1;l--) //check if(up[i][l]<k)break; minn=min(minn,j-l); //取min minn*=k;ans=max(ans,minn); } cout<<ans; } /* 5 5 3 1 2 5 7 1 2 3 4 6 2 4 5 6 9 1 5 7 9 7 3 6 8 10 1 */