ZOJ2067 经典 DP(单调队列优化)

时间:2022-10-19 21:32:42

题目:一个由‘.’和‘#’组成矩形,统计里面'.'组成的矩形的个数。

点击打开链接

自己写挂了,懒得搞了


#include <stdio.h>
#include <string.h>
#define MAX 110
#define inf 0x7fffffff
char a[MAX][MAX];
int count[MAX][MAX];
int n; int min(int x,int y)
{
return x<y?x:y;
} void sum()
{
int i,j;
for(i = ;i <= n; i++)
{
for(j = ;j <= n; j++)
{
if(a[i][j] == '.')
{
count[i][j] = count[i][j - ] + ;
}
}
}
} int Min()
{
int i,j,k;
int ans = ;
for(i = ;i <= n; i++)
{
for(j = ;j <= n; j++)
{
int m = inf;
for(k = i;k <= n && count[k][j]; k++)//1列1列判断 中间断了结束
{
m = min(m,count[k][j]);
ans += m;
}
}
}
return ans;
}
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
for(i = ;i <= n; i++)
scanf("%s",a[i] + );
memset(count,,sizeof(count));
sum();
printf("%d\n",Min());
}
return ;
}