【题解】

  每个格子可以到达的区域是一个菱形,但是我们并不能快速的求和,所以我们可以把原来的草地旋转45度,用二维前缀和快速处理菱形的区域的和。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 1000
#define rg register
using namespace std;
int n,m,k,a[N][N];
LL s[N][N],ans;
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
int main(){
n=read(); k=read();
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++) a[n+i-j][i+j-]=read();
m=n*-;
// for(rg int i=1;i<=m;i++){
// for(rg int j=1;j<=m;j++) printf("%d ",a[i][j]); puts("");
// }
for(rg int i=;i<=m;i++)
for(rg int j=;j<=m;j++) s[i][j]=s[i-][j]+s[i][j-]-s[i-][j-]+a[i][j];
// for(rg int i=1;i<=m;i++){
// for(rg int j=1;j<=m;j++) printf("%lld ",s[i][j]); puts("");
// }
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++){
int x=n+i-j,y=i+j-;
int c1=min(x+k,m),r1=min(y+k,m),c2=max(x-k-,),r2=max(y-k-,);
ans=max(ans,s[c1][r1]-s[c1][r2]-s[c2][r1]+s[c2][r2]);
}
printf("%lld\n",ans);
return ;
}

洛谷 2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver的更多相关文章

  1. P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver

    P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver 最大化一个子矩阵的和. 我们如何去做,dp和贪心呀! 大体题意:给定一个正方形,然后在正方形中求出一个大小已经给定的 ...

  2. HAOI2006 (洛谷P2341)受欢迎的牛 题解

    HAOI2006 (洛谷P2341)受欢迎的牛 题解 题目描述 友情链接原题 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之 ...

  3. 洛谷P2341受欢迎的牛

    传送门啦 这是一个tarjan强连通分量与出度结合的例题. 先明确一下题意,如果这个点(缩点之后的)没有出度,这个点才能成为明星牛(明星牛的定义是:所有牛都喜欢他才可以). 由于我们进行了缩点,所以我 ...

  4. 【洛谷】2990:[USACO10OPEN]牛跳房子Cow Hopscotch【单调队列优化DP】

    P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing ...

  5. 洛谷——P2212 [USACO14MAR]浇地Watering the Fields

    P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...

  6. 洛谷 P3047 [USACO12FEB]附近的牛Nearby Cows

    P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between near ...

  7. 洛谷 P2212 [USACO14MAR]浇地Watering the Fields 题解

    P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...

  8. 洛谷P2881 [USACO07MAR]排名的牛Ranking the Cows(bitset Floyd)

    题意 题目链接 Sol 显然如果题目什么都不说的话需要\(\frac{n * (n - 1)}{2}\)个相对关系 然后求一下传递闭包减掉就行了 #include<bits/stdc++.h&g ...

  9. 洛谷2115 [USACO14MAR]破坏Sabotage

    https://www.luogu.org/problem/show?pid=2115 题目描述 Farmer John's arch-nemesis, Farmer Paul, has decide ...

随机推荐

  1. C的结构体函数

    #include<stdio.h> #include<string.h> struct Test { int age; ]; double score; }std1; //结构 ...

  2. libnids 中哈希表的建立

    //hash.c #include <sys/types.h>#include <sys/time.h>#include <stdio.h>#include < ...

  3. 4. extjs中form中的frame:true表示什么

    转自:https://blog.csdn.net/qiu512300471/article/details/23737217 设置为true时可以为panel添加背景色.圆角边框等,如下图 下面的是f ...

  4. sqlserver2000连接失败,不存在或拒绝访问

    一 看ping 服务器IP能否ping通. 这个实际上是看和远程sql server 2000服务器的物理连接是否存在.如果不行,请检查网络,查看配置,当然得确保远程sql server 2000服务 ...

  5. 给独立搭建的博客启用https的过程

    申请SSL证书 我自己独立搭建的博客部署在阿里云服务器上,因此我就先搜索阿里云启用https的方法,网上有比较详细的讲解,在此提供一个参考网址: https://blog.csdn.net/csluc ...

  6. JDK API文档下载

    java SE 8 API文档:http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-21331 ...

  7. [转].net cookie版购物车

    本文转自:http://www.sulong.cc/article/program/aspx/110613114249.html #region 添加到购物车AddShoppingCar /// &l ...

  8. 继承static的注意点

    继承static的注意点 singleton模式会使用 <?php class Auth { protected static $_instance = null; /** * 单用例入口 * ...

  9. HiveServer2后台运行

    nohup hive --service hiveserver2 & 或者直接: nohup hiveserver2 &

  10. POJ_1018_(dp)

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28273   Accepted:  ...