bzoj1177 [Apio2009]Oil

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

【题解】

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

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

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

【code】

 1 # include <stdio.h>
 2 # include <string.h>
 3 # include <algorithm>
 4 // # include <bits/stdc++.h>
 5
 6 using namespace std;
 7
 8 typedef long long ll;
 9 typedef long double ld;
10 typedef unsigned long long ull;
11 const int M = 1500 + 10;
12 const int mod = 1e9+7;
13
14 # define RG register
15 # define ST static
16
17 int n, m, k, s[M][M];
18 int p[M][M];
19 int a[M][M], b[M][M], c[M][M], d[M][M], ans;
20
21 int main() {
22     scanf("%d%d%d", &n, &m, &k);
23     for (int i=1; i<=n; ++i)
24         for (int j=1, x; j<=m; ++j) {
25             scanf("%d", &x);
26             s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + x;
27         }
28     for (int i=k; i<=n; ++i)
29         for (int j=k; j<=m; ++j)
30             p[i][j] = s[i][j] - s[i-k][j] - s[i][j-k] + s[i-k][j-k];
31
32     // 以(i,j)为右下角
33     for (int i=k; i<=n; ++i)
34         for (int j=k; j<=m; ++j)
35             a[i][j] = max(p[i][j], max(a[i-1][j], a[i][j-1]));
36
37     // 以(i,j)为左下角
38     for (int i=k; i<=n; ++i)
39         for (int j=m-k+1; j; --j) {
40             int C = j+k-1;
41             b[i][j] = max(p[i][C], max(b[i-1][j], b[i][j+1]));
42         }
43
44     // 以(i,j)为右上角
45     for (int i=n-k+1; i; --i)
46         for (int j=k; j<=m; ++j) {
47             int C = i+k-1;
48             c[i][j] = max(p[C][j], max(c[i+1][j], c[i][j-1]));
49         }
50
51     // 以(i,j)为左上角
52     for (int i=n-k+1; i; --i)
53         for (int j=m-k+1; j; --j) {
54             int C1 = i+k-1, C2 = j+k-1;
55             d[i][j] = max(p[C1][C2], max(d[i+1][j], d[i][j+1]));
56         }
57
58     // 两个竖线
59     for (int i=k; i<=n; ++i)
60         for (int j=k+k; j<=m-k; ++j)
61             ans = max(ans, p[i][j] + a[n][j-k] + b[n][j+1]);
62
63     // 两个横线
64     for (int i=k+k; i<=n-k; ++i)
65         for (int j=k; j<=n; ++j)
66             ans = max(ans, p[i][j] + a[i-k][m] + c[i+1][m]);
67
68     // 竖线,横线左
69     for (int i=k; i<=n-k; ++i)
70         for (int j=k; j<=m-k; ++j)
71              ans = max(ans, a[i][j] + c[i+1][j] + d[1][j+1]);
72
73     // 竖线,横线右
74     for (int i=k; i<=n-k; ++i)
75         for (int j=k; j<=m-k; ++j)
76             ans = max(ans, a[n][j] + b[i][j+1] + d[i+1][j+1]);
77
78     // 横线,竖线上
79     for (int i=k; i<=n-k; ++i)
80         for (int j=k; j<=m-k; ++j)
81             ans = max(ans, a[i][j] + b[i][j+1] + d[i+1][1]);
82
83     // 横线,竖线下
84     for (int i=k; i<=n-k; ++i)
85         for (int j=k; j<=m-k; ++j)
86             ans = max(ans, a[i][m] + c[i+1][j] + d[i+1][j+1]);
87
88     printf("%d\n", ans);
89     return 0;
90 }

时间: 2024-10-14 04:25:09

bzoj1177 [Apio2009]Oil的相关文章

【BZOJ 1177】 [Apio2009]Oil

1177: [Apio2009]Oil Time Limit: 15 Sec  Memory Limit: 162 MB Submit: 1044  Solved: 404 [Submit][Status][Discuss] Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地为一个矩形区域,被划分为M×N个小块. Siruseri地质调查局有关于Navalur土地石油储量的估测数据.这些数据表示为M×N个非

[Bzoj 1177][Apio2009] Oil 前缀和+递推

1177: [Apio2009]Oil Time Limit: 15 Sec Memory Limit: 162 MB Submit: 1569 Solved: 632 [Submit][Status][Discuss] Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地为一个矩形区域,被划分为M×N个小块. Siruseri地质调查局有关于Navalur土地石油储量的估测数据.这些数据表示为M×N个非负整

BZOJ 1177 [Apio2009]Oil(递推)

[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1177 [题目大意] 给出一个矩阵,从中选出3个k*k且不相交的矩阵,使得其总和最大 [题解] 只要处理四个方向的前缀最大值,就可以分类比较得到答案. [代码] #include <cstdio> #include <algorithm> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;i++) #d

【BZOJ】【1177】【APIO2009】Oil

DP 找出三个正方形,可以转化为将整个油田切成三个矩形块,每块中各找一个正方形区域,切的形式只有6种,分类更新ans即可 题解:http://trinklee.blog.163.com/blog/static/238158060201482371229105/ 另:这题一般的快速读入不知为何会RE,但是题解里这位大神的快速读入就能AC……跪了跪了 1 /************************************************************** 2 Problem

洛谷P3625 - [APIO2009]采油区域

Portal Description 给出一个\(n\times m(n,m\leq1500)\)的矩阵,从中选出\(3\)个互不相交的\(k\times k\)方阵,使得被选出的数的和最大. Solution 奇怪做法... 三个矩形分别在三个部分中,把矩形划分成三部分只有这六种.首先搞出\(s[i][j]\)表示以\((i,j)\)为右下角的\(k\times k\)方阵的和,然后搞出\(f_1[i][j]\)表示\((1,1)-(i,j)\)中\(s\)的最大值,\(f_2[i][j]\)

[BZOJ1177][BZOJ1178][BZOJ1179]APIO2009解题报告

抱着好奇心态去开始做APIO的往年试题感受一下难度 Oil Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地为一个矩形区域,被划分为M×N个小块. Siruseri地质调查局有关于Navalur土地石油储量的估测数据.这些数据表示为M×N个非负整数,即对每一小块土地石油储量的估计值. 为了避免出现垄断,政府规定每一个承包商只能承包一个由K×K块相连的土地构成的正方形区域. AoE石油联合公司由三个承包商组

UVa 572 - Oil Deposits【图DFS】

Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It

hdu 4185 Oil Skimming(二分匹配)

Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 883    Accepted Submission(s): 374 Problem Description Thanks to a certain "green" resources company, there is a new profitable

Oil Deposits hdu-1241 DFS

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyze