zoukankan      html  css  js  c++  java
  • 洛谷 P1736 创意吃鱼法

    和最大正方形很像。
    记得对角线有两条
    还有2500不要开成3000,否则会mle

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #define REP(i, a, b) for(int i = (a); i < (b); i++)
    #define _for(i, a, b) for(int i = (a); i <= (b); i++)
    using namespace std;
    
    const int MAXN = 2512;
    int f[MAXN][MAXN], x[MAXN][MAXN], y[MAXN][MAXN];
    int a[MAXN][MAXN], n, m, ans, now;
    
    int main()
    {
    	scanf("%d%d", &n, &m);
    	_for(i, 1, n)
    		_for(j, 1, m)
    			scanf("%d", &a[i][j]);
    	 
    	_for(i, 1, n)
    		_for(j, 1, m)	
    		{
    			if(a[i][j])
    			{	
    				f[i][j] = min(f[i-1][j-1], min(y[i][j-1], x[i-1][j])) + 1;
    				ans = max(ans, f[i][j]);
    			}
    			else 
    			{
    				x[i][j] = x[i-1][j] + 1;
    				y[i][j] = y[i][j-1] + 1;
    			}
    	}
    	
    	memset(f, 0, sizeof(f));
    	memset(x, 0, sizeof(x));
    	memset(y, 0, sizeof(y));
    	
    	_for(i, 1, n)
    		for(int j = m; j >= 1; j--)	
    		{
    			if(a[i][j])
    			{	
    				f[i][j] = min(f[i-1][j+1], min(y[i][j+1], x[i-1][j])) + 1;
    				ans = max(ans, f[i][j]);
    			}
    			else 
    			{
    				x[i][j] = x[i-1][j] + 1;
    				y[i][j] = y[i][j+1] + 1;
    			}
    	}
    
    	printf("%d
    ", ans);
    	
    	return 0;
    }
  • 相关阅读:
    Codeforces Round #420 (Div. 2) A-E
    Codeforces Round #419 (Div. 2) A-E
    Bzoj4423 [AMPPZ2013]Bytehattan
    51nod1471 小S的兴趣
    Bzoj2629 binomial
    51nod1056 最长等差数列 V2
    51nod1055 最长等差数列
    51nod1110 距离之和最小 V3
    20. 有效的括号
    155.最小栈
  • 原文地址:https://www.cnblogs.com/sugewud/p/9819380.html
Copyright © 2011-2022 走看看