P1387 最大正方形 /// DP

题目大意:

https://www.luogu.org/problemnew/show/P1387

题解

第一份方法

原数组

0 0 0 1

1 1 1 1

0 1 1 1

1 1 1 1

dp[i][j]:

0 0 0 1

1 1 1 1

0 1 2 2

1 1 2 3

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,dp[105][105];
    while(~scanf("%d%d",&n,&m)) {
        int ans=0;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++) {
                scanf("%d",&dp[i][j]);
                if(dp[i][j]) dp[i][j]=min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]))+1;
                ans=max(ans,dp[i][j]);
            }
        printf("%d
",ans);
    }

    return 0;
}
View Code
原文地址:https://www.cnblogs.com/zquzjx/p/9333119.html