P1387 最大正方形

中文题

 

想法:

定义 dp[i][j] 代表以(i,j) 为右下角的最大正方形的边长

 

 图片来源:https://www.luogu.com.cn/blog/Panthera/solution-p1387

 

#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <math.h>
#include <cstdio>
#include <iomanip>
#include <time.h>
#include <bitset>
#include <cmath>
#include <sstream>
#include <iostream>
#include <cstring>

#define LL long long
#define ls nod<<1
#define rs (nod<<1)+1
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f

const double eps = 1e-10;
const int maxn = 100 + 10;
const LL mod = 1e9 + 7;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}
using namespace std;

int f[maxn][maxn];
int a[maxn][maxn];

int main() {
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= m;j++) {
            cin >> a[i][j];
            if (a[i][j]) {
                f[i][j] = min(f[i-1][j-1],min(f[i-1][j],f[i][j-1])) + 1;
                ans = max(ans,f[i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

当然这题 单调队列也可以做

posted @ 2020-03-13 22:12  _Ackerman  阅读(220)  评论(0编辑  收藏  举报