/**/
/*
http://acm.hnu.cn:8080/online/?action=problem&type=show&id=10180
*/
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
#include
<
iostream
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using
namespace
std;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int
map[
501
][
501
];
int
n, m;
int
x, y;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void
Mark()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int i, j;
for(j = 2; j <= n; j++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(i = 2; i <= n; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(map[i][j] == 0)
continue;
if(map[i - 1][j] == map[i][j - 1])
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
bool flag = true;
int k, w;
for(w = i - map[i - 1][j]; w <= i; w++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(k = j - map[i - 1][j]; k <= j; k++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(map[w][k] == 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flag = false;
break;
}
}
}
if(flag)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
map[i][j] = map[i - 1][j] + 1;
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
map[i][j] = map[i - 1][j];
}
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
map[i][j] = map[i - 1][j] > map[i][j - 1] ? map[i - 1][j] : map[i][j - 1];
}
}
}
}
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int
GetMaxSquare()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int max = 0;
for(int i = 1; i <= n; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int j = 1; j <= n; j++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(map[i][j] > max)
max = map[i][j];
}
}
return max;
}
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void
Initialize()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
for(int i = 1; i <= n; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int j = 1; j <= n; j++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
map[i][j] = 1;
}
}
}
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int
main()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int i,j;
cin >> n >> m;
Initialize();
for(i = 0; i < m; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cin >> x >> y;
map[x][y] = 0;
}
Mark();
cout << GetMaxSquare() << endl;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
dp题目, 我的大概思路是这样
记 f(i, j)表示的是以坐标(i, j)为矩形右下角顶点的最大正方形的个数,那么不难发现
当f(i -1, j) == f(i, j - 1)的时候, f(i, j) 可能取得f(i - 1, j) + 1, 只要遍历一下整个矩阵就搞定了(这个可以优化)
而当f(i -1, j) != f(i, j - 1)的时候, f(i, j) = f(i - 1, j) + 1