CodeForces 429B Working out(dp,四个角递推)

CTF-Web习题:2019强网杯 UPLOAD 本题涉及知识点:代码审计、文件上传漏洞、反序列化漏洞 阅读详情

B. Working out

Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.

Iahub starts with workout located at line 1 and column 1. He needs to finish with workout a[n][m]. After finishing workout a[i][j], he can go to workout a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout a[n][1] and she needs to finish with workout a[1][m]. After finishing workout from cell a[i][j], she goes to either a[i][j + 1] or a[i - 1][j].

There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.

If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105).

Output

The output contains a single number — the maximum total gain possible.

Sample test(s)
Input
3 3
100 100 100
100 1 100
100 100 100
Output
800
dp思路:可以枚举每个可能相遇的点所产生的最大情况
dp1[i][j] 从(1,1)到(i,j)的最大值
dp2[i][j] 从(n,m)到(i,j)的最大值
dp3[i][j] 从(m,1)到(i,j)的最大值
dp1[i][j] 从(1,n)到(i,j)的最大值

ans为最终结果:
由于遍历的每个点是,可以分为四个部分,(1,1)->(i,j)+(i,j)->(n,m) + (n,1)->(i,j) + (1,m)->(i,j)
因此可以用ans更新四部分和的最大值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#define LL long long
#define WW freopen("in.txt","r",stdin)
#define RR freopen("out.txt","w",stdout)
#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1010;

int dp1[maxn][maxn],dp2[maxn][maxn],dp3[maxn][maxn],dp4[maxn][maxn];
int a[maxn][maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp1[i][j] = max(dp1[i-1][j],dp1[i][j-1]) + a[i][j];
        }
    }

    for(int i=n;i>=1;i--)
    {
        for(int j=m;j>=1;j--)
        {
            dp2[i][j] = max(dp2[i+1][j],dp2[i][j+1]) + a[i][j];
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=m;j>=1;j--)
        {
             dp3[i][j] = a[i][j] + max(dp3[i-1][j], dp3[i][j+1]);
        }
    }

    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=m;j++)
        {
            dp4[i][j] = a[i][j] + max(dp4[i][j-1], dp4[i+1][j]);
        }
    }
    int ans = 0;
    for(int i=2;i<n;i++)
    {
        for(int j=2;j<m;j++)
        {
            ans = max(ans,dp1[i-1][j]+dp2[i+1][j]+dp3[i][j+1]+dp4[i][j-1]);
            ans = max(ans,dp1[i][j-1]+dp2[i][j+1]+dp3[i-1][j]+dp4[i+1][j]);
        }
    }
    printf("%d\n",ans);
    return 0;
}


CH340以及CH系列USB转串口驱动下载 在之前使用USB转串口时,很多时候大家可能会不知道去哪下载驱动,然后百度随便下载一个,但往往鱼龙混杂且版本不一,所以今天特意整理一下CH340驱动以及CH系列的官方驱动下载地址,方便大家进行下载也方便自己后期查找,所有链接皆指向官方下载链接,每次下载都可获取官方当前最新驱动。 CH340/CH341 Windows驱动下载链接:CH341SER.EXE下载链接 Linux驱动下载链接:CH341SER_LINUX.ZIP下载链接 Andr... 阅读详情

相关推荐

LED单元板驱动(HUB75接口)

开始之前先吐槽一下,搜这个的资料。要么都是Arduino,要么单片机的收费。小小的一个LED单元板,凭什么? 用Arduino是你速度快还是我ST,树莓派不好用?收费更离谱,这点东西还藏私?给你个中指凸。把原理都写出来看你怎么收费。 一、接口定义及原理 如图,有两个RGB通道,共占用6个IO。剩下的ABCDE为地址通道,LAT为行数据锁存通道,CLK为数据时钟,OE为低电平使能LED显示。图片这里没有E,证明它是16扫的,有E就会把B上面的地改为E。这样就是5位,2的5次方32扫。1.

a3748622的博客 3万+

Working out (dp动态规划)

 Working out Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i]...

Learning_is_endless的博客 1095

资产监测设备中130dBm的GPS信号注入天线端口,C/N0一般是多少?

笔者的团队一直从事于资产监测设备的开发,在开发过程中,涉及到很多细节的问题,针对新入职的同事来说较为陌生。同时,在团队外,还有需要对智能硬件终端开发感兴趣的用户。基于此背景下,笔者将在下面的内容主要介绍资产监测设备以及对设备中的GPS相关的问题:130dBm的GPS信号注入天线端口,C/N0一般是多少?作出详细的解答。 资产监测设备概述: 资产监测设备是基于物联网通信技术基础上的智能硬件终端,其主要作用是帮助用户监测资产在仓库、运输途中、交付整个流通环节中,提供资产的实时位置与状态参数。用户只需要登录资产

瑞奇聊通信模组 1229

Working out(详解)

Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and mcolumns. Let number a[i][j] represents...

m0_37579232的博客 513

ESP32连接PDM麦克风操作指南:新手入门必看

手把手教你如何将ESP32与PDM麦克风连接,采集音频数据并用于音频分类应用。内容涵盖硬件接线、代码配置及实际调试技巧,适合初学者快速上手esp32在声音识别场景中的使用。

weixin_42590539的博客 1329

一张图看懂中国民航适航审定体系:从适航司到审定中心,到底谁管谁?

本文深入解析中国民航适航审定体系,从立法层到执行层的完整链条,揭示适航管理的金字塔结构和核心流程。涵盖适航司、审定中心等关键机构职能,以及型号审定、生产许可审定等全生命周期管理,展现中国适航体系的特色实践与创新探索。

weixin_30896511的博客 475

Working out CodeForces - 429B (四个角dp)

Working out CodeForces - 429B Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines

codeswarrior的博客 499

电价预测的Transformer实战:从注意力机制到超长序列建模

本文深入探讨了Transformer模型在电价预测领域的实战应用,对比了其与LSTM在处理长序列依赖和误差累积问题上的优劣。文章详细解析了自注意力机制的原理,并提供了处理超长序列的位置编码方法、构建专用预测模型的完整PyTorch代码,以及防止信息泄露的关键技巧。通过实战对比,展示了Transformer在并行计算、长距离建模和预测精度上的显著优势,并分享了应对极端波动和提升模型效率的高级优化策略。

f6g7h8i9j的博客 540

B. Working out (递推dp )

B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Summer is coming! It's time for Iahub and Ia

略略略的博客 483

【无线通信】射频杂散(RF Spurious Emissions)

射频杂散(RF Spurious Emissions)是指在无线通信系统中,除了在指定频率范围内的预期信号之外,任何不需要的或非预期的射频信号。这些杂散信号可能会干扰其他通信系统,降低系统性能,并违反无线电通信法规。射频杂散通常包括谐波、次谐波、互调产物和其他非线性失真所产生的信号。

qq_38801607的博客 5422

Ubuntu新手必看:3种方法快速查看和编辑JSON文件(附jq安装指南)

本文为Ubuntu新手详细介绍了三种查看和编辑JSON文件的核心方法:命令行利器jq、灵活脚本Python以及直观的图形化编辑器(如VS Code)。文章重点解析了jq的安装与核心用法,并对比了各方案的优缺点,帮助用户根据快速查询、复杂处理或直观编辑等不同场景,选择最合适的工具,从而高效处理JSON数据。

weixin_29229989的博客 415

四角递推(CF Working out,动态规划递推)

题目:假如有A,B两个人,在一个m*n的矩阵,然后A在(1,1),B在(m,1),A要走到(m,n),B要走到(1,n),两人走的过程中可以捡起格子上的数字,而且两人速度不一样,可以同时到一个点(哪怕这个点离A很近,离B很远),现在A,B起码相遇于一个点点,相遇点的数字A,B都得不到,求最后A,B总数字之和的最大值 B. Working out Summer is coming! It's t...

weixin_33918357的博客 204

ubuntu emto-cpa安装与编译

ubuntu emto-cpa安装与编译

qq_45834835的博客 1435

Working out CodeForces - 429B(四个角递推+dp)

传送门 题意:要求两个人必须相遇一次,A这个人只能从[1,1]到[n,m],B这个人只能从[n,1]到[1,m],A只能向下向右走,B只能向上向右走,问如何选取使得最后值最大。 题解:先分别从四个递推,然后枚举相遇的块,相遇的块肯定不能是边界,因为边界必然有多个块相碰,只能枚举中间的块,但是中间的块对于A只能向下或者向右,如果A是从上面来的,那么必然B是从右边来的,并且A继续向下走,B继续向右...

肘子的博客 248

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

CodeForces 429B Working out // 递推dp

题目描述CodeForces 429B Working out解题思路题目大意: 有n*m个格子, 走过一个格子可以得到相应的分数. A 从(1,1)开始沿 下 或 右 走到(n,m) B 从(n,1)沿 上 或 右 走到(1,m) 两人路径有且只能有一个格子重合(重合格子的分数不算), 求两人分数之和的最大值.首先要保证只有一个格子重合,那么只可能是以下两种情况: 1) A向右走,相遇后

FZU_zyt的专栏_(:з」∠)_ 1379

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

[dp] Codeforces 429B B. Working out

题目链接: http://codeforces.com/problemset/problem/429/B PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST B. Working out time limit per test 2 seconds memory li

cc_again的专栏 9715

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Working out - CODEFORCES, 429B 动态规划

题目链接 CODEFORCES 429B Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Le

呼,是出一口气;吸,是争一口气! 1937

G - Working out CodeForces - 429B (四个角递推)

递推,四个角往中间推 挺有意义的题目 要注意路径不会多次重叠的情况。 #include"stdio.h" #include"algorithm" #include"string.h" #include"iostream" using namespace std; int dp1[1050][1005],dp2[1005][1005],dp3[1005][1005],dp4[1005][...

云乐 180

CodeForces - 429B Working out 简单DP

Working out CodeForces - 429B 一个 n×mn\times mn×m 的矩阵 aaa ,a[i][j]a[i][j]a[i][j] 表示 iii 行 jjj 列可以燃烧的卡路里,第一个人从 a[1][1]a[1][1]a[1][1] 开始,到 a[n][m]a[n][m]a[n][m] 结束,选择 a[i][j]a[i][j]a[i][j] 之后,他可以继续选择 a[i...

wineandchord 194

Codeforces 429B Working out:dp【枚举交点】

题目链接:http://codeforces.com/problemset/problem/429/B 题意:   给你一个n*m的网格,每个格子上有一个数字a[i][j]。   一个人从左上角走到右下角,一个人从左下角走到右上角,要求两条路径有且仅有一个交点。   问你除去交点格子上的数字,路径上数字之和最大是多少。 题解:   表示状态:     dp[i][j]...

a1392136的博客 156

Codeforces 429B Working out

Iahub只能向右或下走

xlp的acm专栏 1036

CodeForces 429 B Working out(递推dp)

  题目连接:B. Working out   我想了很久都没有想到怎么递推,看了题解后试着自己写,结果第二组数据就 wa 了,后来才知道自己没有判选择的两条路径是否只是一个交点。   大概思路是:先预处理出每个格子到四个角落格子的路径最大数值,然后枚举两个人相遇的交点格子,枚举 A、B 的进来和出去方式(记两个线路为 1 和 2,考虑一个公共点,1 为左进右出,2 为下进上出;1...

aidiao7379的博客 135

codeforces 429B B. Working out 详解(dp)

D. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Summer is coming! It's time for Iahub and Iahubina t

K键盘里的青春K 1889

B. Working out 四角dp

https://codeforces.com/problemset/problem/429/B 这个题目之前写过,不过好像。。忘记了,今天又没有写出来,应该之前没有想明白。。。 这个应该算一个四角dp(网上说的,感觉很符合),所以呢就是要从四个角进行dp, 就是先对四个角到对角的一个dp,然后就是枚举每一个位置,找其中最大的。 #include<cstdio> ...

weixin_30412167的博客 112

CodeForces 429B——Working out 【DP】

题目传送门 Summer is coming! It’s time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] rep...

NIRVANA REBIRTH 264
上一篇: 常用分割线递推方程
下一篇: HDU DP
__铭
博客等级 码龄12年 35粉丝 274原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值