您的位置:首页 > 其它

Hdu 1505 City Game (DP求最大面积)

2014-03-11 17:17 357 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505    
思路: 跟1506 很相似,只是需要对每行都扫描,dp是O(n^2)的。

注意:用%s输入或者cin 能够滤掉多余空格。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000+5
int map[maxn][maxn];
int up[maxn],l[maxn],r[maxn];
int main(){
int t ;
int n,m;
char tmp[2];
scanf("%d",&t);
while(t--){
memset(up,0,sizeof(up));
scanf("%d%d%*c",&n,&m);
int ans = 0;
for (int i = 1; i <= n; i++)
{
up[0] = up[m+1] = -1;
for (int j = 1; j <= m; j++)
{
l[j] = r[j] = j;
scanf("%s",tmp);
if(tmp[0] == 'F'){
up[j]++;
}else up[j] = 0;
while(up[ l[j]-1 ] >= up[j]){
l[j] = l[ l[j]-1 ];
}
}
for (int j = m; j > 0; j--)
{
while(up[ r[j]+1 ] >= up[j]){
r[j] = r[ r[j]+1 ];
}
ans = max(ans,(r[j]-l[j]+1)*(up[j]));
}
}
printf("%d\n",ans*3);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DP 求最大面积