您的位置:首页 > 其它

hdu 4517 小小明系列故事——游戏的烦恼

2013-03-23 21:47 239 查看
题目: 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 ;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: