题目: http://acm.hdu.edu.cn/showproblem.php?pid=4517
解法:动态规划+滚动数组
#include <iostream>
#include <cstdio>
using namespace std ;
const int maxn = 2010 ;
int n,m;
char map[maxn][maxn] ;
int row[2][maxn]={0} , col[2][maxn]={0} ;
int test(int x,int y)
{
int count =0 ;
memset(row,0,sizeof(row)) ;
memset(col,0,sizeof(col)) ;
int i,j ;
for(i=n-1;i>=0 ;i--)
{
for(j=m-1;j>=0;j--)
{
if(map[i][j] == '*')
{
row[i&1][j] = row[i&1][j+1] +1 ;
if(row[i&1][j]>=y )
{
col[i&1][j] =1 ;
if(row[(i+1)&1][j] >= y)
{
col[i&1][j] += col[(i+1)&1][j] ;
}
if(col[i&1][j] >=x )
{
count ++ ;
}
}
else
{
col[i&1][j] = 0 ;
}
}
else
{
row[i&1][j] =0 ;
}
}
}
return count ;
}
int main()
{
while(cin>>n>>m,n)
{
int i ,j;
int x,y ;
cin>>x>>y ;
for(i=0;i<n;i++)
{
cin>>map[i] ;
}
int sum =test(x,y);
if(x!=y)
sum += test (y,x);
cout <<sum <<endl;
}
return 0 ;
}