P2733 家的范围 Home on the Range-弱DP

P2733 家的范围 Home on the Range

思路 :转化为以每个点为右下角的 最大正方形的边长

#include<bits/stdc++.h>
using namespace std;
#define maxn 303
int tong[maxn],dp[maxn][maxn],n;
char a[maxn][maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%s",a[i]+1);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(a[i][j]=='1')
                dp[i][j]=min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1]))+1;
            else dp[i][j]=0;
            for(int p=dp[i][j]; p>1; p--)
                tong[p]++;
        }
    for(int i=2; i<=n; i++)
        if(tong[i]!=0)
            printf("%d %d
",i,tong[i]);
    return 0;
}

  

原文地址:https://www.cnblogs.com/SDUTNING/p/10302780.html