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;
}
思路: 跟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;
}
相关文章推荐
- HDU 1505 City Game-dp-(最大子矩阵模型)
- HDU 1505 City Game (单调栈+最大子矩阵面积)
- HDU 1505 1506 2830 2870求最大矩阵面积 DP
- HDU 1505 City Game【矩阵的最大面积】
- hdu 1505 City Game 最大矩形面积 单调队列
- HDU 1505 City Game(DP求二维最大子矩阵)
- HDU 1505 City Game (最大子矩形面积)
- HDU 1505 City Game(dp)
- hdu 1505 City Game(dp)
- hdu 1505 City Game(最大子矩阵)
- hdu 1505 (求一个最大的空闲矩形的面积)
- 【DP求最大子矩阵面积】hdu 1506
- HDU_1505_矩阵中的最大矩形_dp
- HDU 1056 Largest Rectangle in a Histogram(dp)(求最大的矩形面积)
- HDU-1505-City Game【dp】【思维】
- HDU 1505 City Game(01矩阵 dp)
- HDU 1505 City Game(DP)
- UVALive 3029 City Game 悬线法求最大子矩阵面积 dp
- HDU 1505 City Game (DP)
- City Game - HDU 1505 最大内部矩形