首页 技术 正文
技术 2022年11月21日
0 收藏 406 点赞 2,997 浏览 1064 个字

题目链接

bzoj3111: [Zjoi2013]蚂蚁寻路

题解

发现走出来的图是一向上的凸起锯齿状

对于每个突出的矩形dp一下就好了

代码

/*
*/
#include<cstdio>
#include<algorithm>
const int maxn = 127;
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-')f = -1;c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
const int INF = 0x3f3f3f3f;
const int rp = 0x7fffffff;
int n,m,k;
int sum[maxn][maxn],a[maxn][maxn];
int g[maxn][25][maxn][2];
int dp[maxn][maxn][maxn];
int main() {
int ans = -0x3f3f3f3f;
n = read(),m = read(),k = read();
k = k << 1 | 1;
for(int i = 1;i <= n;++ i) for(int j = 1;j <= m;++ j) a[i][j] = read(), sum[i][j] = sum[i - 1][j] + a[i][j];
for(int i = 1;i <= k;++ i) for(int j = 1;j <= n;++ j)
g[0][i][j][0] = g[0][i][j][1] = dp[0][i][j] = -INF;
for(int i = 1;i <= n;++ i) for(int j = 1;j <= m;++ j) {
for(int p = 1;p <= k;++ p) {
for(int h = i;h;-- h)
dp[j][p][h] = std::max(dp[j - 1][p][h],g[j - 1][p - 1][h][p % 2]) - sum[h - 1][j] + sum[i][j];
g[j][p][1][0] = -INF;
for(int h = 2;h <= i;++ h)
g[j][p][h][0] = std::max(dp[j][p][h - 1],g[j][p][h - 1][0]);
g[j][p][i][1] = -INF;
for(int h = i - 1;h;-- h)
g[j][p][h][1] = std::max(dp[j][p][h + 1],g[j][p][h + 1][1]);
}
ans = std::max(ans,std::max(dp[j][k][i],g[j][k][i][0]) );
}
printf("%d\n",ans);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918