hdu 4846 Big Barn【dp】

http://acm.hdu.edu.cn/showproblem.php?pid=4846

求矩阵中最大的仓库正方形

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int n, t;
int a[1010][1010];
int b[1010][1010];

int main()
{
    while (scanf("%d %d", &n, &t) != EOF)
    {
        for (int i = 0;i <= n;i++)
            for (int j = 0;j <= n;j++)
                a[i][j] = 1;

        int u, v;
        //memset(b, 0, sizeof(b));
        while (t--)
        {
            scanf("%d%d", &u, &v);
            a[u][v] = 0;
        }
        for (int i = 1;i <= n;i++)
        {
            b[i][1] = a[i][1];
            b[1][i] = a[1][i];
        }
        for(int i=2;i<=n;i++)
            for (int j = 2;j <= n;j++)
            {
                if (a[i][j] == 1)
                    b[i][j] = min(b[i - 1][j - 1], min(b[i - 1][j], b[i][j - 1])) + 1;
                else
                    b[i][j] = 0;
            }
        int ans = 0;
        for (int i = 1;i <= n;i++)
            for (int j = 1;j <= n;j++)
            {
                ans = max(ans, b[i][j]);
            }
        printf("%d\n", ans);
    }
    return 0;
}

你可能感兴趣的:(----------DP,dp)