HDU1505--City Game(动态规划)(1506加强版)

这道题和1506差不多,多加了一维,只要求出每个F点上面的F点个数,然后压到一行中,就和1506一样了。

#include 
#include 
#include 
#include 
#include 
#define maxn 1005
using namespace std;

struct Map
{
	char c[5];
	int num;
	int left,right;
}map[maxn][maxn];

int main()
{
	int t,n,m,i,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		getchar();
		for(j=1;j<=m;j++)
			map[0][j].num=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				scanf("%s",map[i][j].c);
				if(map[i][j].c[0]=='F')
					map[i][j].num=map[i-1][j].num+1;
				else
					map[i][j].num=0;
				map[i][j].left=map[i][j].right=j;
			}
		}
		int max=0;
		for(i=1;i<=n;i++)
		{
			map[i][0].num=map[i][m+1].num=-1;
			for(j=1;j<=m;j++)
			{
				while(map[i][j].num<=map[i][map[i][j].left-1].num)
					map[i][j].left=map[i][map[i][j].left-1].left;
			}
			for(j=m;j>=1;j--)
			{
				while(map[i][j].num<=map[i][map[i][j].right+1].num)
					map[i][j].right=map[i][map[i][j].right+1].right;
			}
			for(j=1;j<=m;j++)
			{
				if(map[i][j].c[0]=='F')
				{
					int sum=(map[i][j].right-map[i][j].left+1)*map[i][j].num;
					if(sum>max)
						max=sum;
				}
			}
		}
		printf("%d\n",max*3);
	}
	return 0;
}


你可能感兴趣的:(动态规划)