zoukankan      html  css  js  c++  java
  • bzoj1177 [Apio2009]Oil

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1177

    【题解】

    发现分割方案就只有6种……

    稍微分点类,然后大力算出以(i,j)为左上角/左下角/右上角/右下角的二维前缀/后缀内的max正方形即可。

    然后大力分六种情况讨论一波,注意边界。

    # include <stdio.h>
    # include <string.h>
    # include <algorithm>
    // # include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    const int M = 1500 + 10;
    const int mod = 1e9+7;
    
    # define RG register
    # define ST static
    
    int n, m, k, s[M][M];
    int p[M][M];
    int a[M][M], b[M][M], c[M][M], d[M][M], ans;
    
    int main() {
        scanf("%d%d%d", &n, &m, &k);
        for (int i=1; i<=n; ++i)
            for (int j=1, x; j<=m; ++j) {
                scanf("%d", &x);
                s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + x;
            }
        for (int i=k; i<=n; ++i)
            for (int j=k; j<=m; ++j)
                p[i][j] = s[i][j] - s[i-k][j] - s[i][j-k] + s[i-k][j-k];
        
        // 以(i,j)为右下角 
        for (int i=k; i<=n; ++i) 
            for (int j=k; j<=m; ++j) 
                a[i][j] = max(p[i][j], max(a[i-1][j], a[i][j-1]));
        
        // 以(i,j)为左下角 
        for (int i=k; i<=n; ++i)
            for (int j=m-k+1; j; --j) {
                int C = j+k-1; 
                b[i][j] = max(p[i][C], max(b[i-1][j], b[i][j+1]));
            }
        
        // 以(i,j)为右上角
        for (int i=n-k+1; i; --i) 
            for (int j=k; j<=m; ++j) {
                int C = i+k-1;
                c[i][j] = max(p[C][j], max(c[i+1][j], c[i][j-1]));
            }
        
        // 以(i,j)为左上角
        for (int i=n-k+1; i; --i)
            for (int j=m-k+1; j; --j) {
                int C1 = i+k-1, C2 = j+k-1;
                d[i][j] = max(p[C1][C2], max(d[i+1][j], d[i][j+1]));
            }
        
        // 两个竖线    
        for (int i=k; i<=n; ++i)
            for (int j=k+k; j<=m-k; ++j)
                ans = max(ans, p[i][j] + a[n][j-k] + b[n][j+1]);
        
        // 两个横线
        for (int i=k+k; i<=n-k; ++i)
            for (int j=k; j<=n; ++j) 
                ans = max(ans, p[i][j] + a[i-k][m] + c[i+1][m]);
        
        // 竖线,横线左
        for (int i=k; i<=n-k; ++i)
            for (int j=k; j<=m-k; ++j) 
                 ans = max(ans, a[i][j] + c[i+1][j] + d[1][j+1]); 
    
        // 竖线,横线右
        for (int i=k; i<=n-k; ++i)
            for (int j=k; j<=m-k; ++j)
                ans = max(ans, a[n][j] + b[i][j+1] + d[i+1][j+1]);
        
        // 横线,竖线上
        for (int i=k; i<=n-k; ++i)
            for (int j=k; j<=m-k; ++j) 
                ans = max(ans, a[i][j] + b[i][j+1] + d[i+1][1]);
        
        // 横线,竖线下
        for (int i=k; i<=n-k; ++i)
            for (int j=k; j<=m-k; ++j) 
                ans = max(ans, a[i][m] + c[i+1][j] + d[i+1][j+1]); 
        
        printf("%d
    ", ans); 
        return 0;
    }
    View Code
  • 相关阅读:
    【转】Linux 查看CPU信息、机器型号等硬件信息
    荐书
    软件架构的5种视图
    MariaDB 10.4.12 Stable Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. 亲测有效
    配置MariaDB允许远程连接的方法
    MariaDB 10.4.12 Stable 绿色版下载安装
    最完整的Markdown基础教程
    Java开发环境配置 JDK开发环境配置
    centos7 断电导致 generating /run/initramfs/rdsosreport.txt 问题
    高性能分布式锁-redisson
  • 原文地址:https://www.cnblogs.com/galaxies/p/bzoj1177.html
Copyright © 2011-2022 走看看