CDUTCM OJ 1293Building
1293: Building
时间限制: 1 Sec 内存限制: 128 MB
提交: 6 解决: 4
题目描述
CTJ team were going to build a house which needed a square land. Now they are inspecting a large area of land, but there are pits or large rocks on the ground, which could not be covered by house. So you are giving the terrain. Can you help them find the largest area of the house?
输入
The first line has two integers n, m (1<=n, m<=1000),for the entire land surface. Followed by n lines, each line of m numbers separated by spaces. 0 means that the block of land has pits or rocks, and 1 means that the block of land is intact.
输出
An integer, the length of the largest square.
样例输入
4 4
0 1 1 1
1 1 1 0
0 1 1 0
1 1 0 1
样例输出
2
PS:额,真的忍不住骂脏话,这sb题 ,就一很简单的动态规划,但乍一看还以为是搜索,但一看数据范围1000*1000,就想到了动态规划,但到最后也没想出转移方程,哎,还是太菜。直接看代码吧。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1005][1005],b[1005][1005];
int n,m;
int main(){
int ans,i,j;
while(cin>>n>>m){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
ans=0;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
scanf("%d",&a[i][j]);
if(a[i][j]==0){
b[i][j]=0;
}
else if(a[i][j]==1){
if(b[i-1][j-1]==0){
b[i][j]=1;
}
else{
b[i][j]=min(b[i-1][j],b[i][j-1])+1;
}
}
ans=max(b[i][j],ans);
}
}
cout<<ans<<endl;
}
return 0;
}
本文介绍了一个动态规划问题,目标是在一块包含障碍物的土地上找到能够建造的最大面积的正方形房屋。通过动态规划算法,文章提供了详细的解决方案和代码实现。
459

被折叠的 条评论
为什么被折叠?



