水题,直接贴代码。
//poj 3051
//sep9
#include <iostream>
using namespace std;
char g[1024][128];
int dp[1024][128];
int w,h,ans;
int search(int x,int y)
{dp[x][y]=1;if(x+1<h&&g[x+1][y]=='*'&&dp[x+1][y]==0)dp[x][y]+=search(x+1,y);if(x-1>=0&&g[x-1][y]=='*'&&dp[x-1][y]==0)dp[x][y]+=search(x-1,y); if(y+1<w&&g[x][y+1]=='*'&&dp[x][y+1]==0)dp[x][y]+=search(x,y+1);if(y-1>=0&&g[x][y-1]=='*'&&dp[x][y-1]==0)dp[x][y]+=search(x,y-1);ans=max(ans,dp[x][y]); return dp[x][y];
}int main()
{memset(dp,0,sizeof(dp));scanf("%d%d",&w,&h);int i,j;for(i=0;i<h;++i)scanf("%s",g[i]);ans=0;for(i=0;i<h;++i)for(j=0;j<w;++j)if(dp[i][j]==0&&g[i][j]=='*')search(i,j); printf("%d",ans);return 0;
}