Codeforces 429B Working out (dp 数字三角形变形)

保姆级教程:用北醒TFmini-i-CAN雷达给PixHawk飞控加装‘眼睛’,实现自动避障与定高 经过多次测试,前向雷达的最佳安装位置是机架前部下方5-10cm处,倾斜角度20-30度。电源方面,建议为CAN设备单独供电,避免电机启动时的电压骤降导致数据异常。北醒TFmini-i-CAN雷达与PixHawk飞控的组合,为DIY爱好者打开了低成本实现智能避障的大门。实际部署时,需确保整个CAN网络的波特率一致(TFmini-i默认为250kbps),每个设备具有唯一ID。雷达的安装角度也直接影响检测效果,建议通过3D打印支架将雷达向前下方倾斜15-30度。当使用多个雷达时,需为每个设备创建独立的参数组。 阅读详情
Working out
time limit per test:2 seconds
memory limit per test:256 megabytes

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.

Examples
Input
3 3
100 100 100
100 1 100
100 100 100
Output
800
Note

Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3].


题目链接:http://codeforces.com/problemset/problem/429/B


题目大意:两个人,一个从左上到右下,一个从左下到右上,要求只相遇一个点,相遇的点权值不算,求最大总权值

题目分析:四个角求四次,对于两个人枚举两种情况(A从上往下B从左往右,A从左往右B从下往上)

#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int const MAX = 1e3 + 5;
ll a[MAX][MAX], dp1[MAX][MAX], dp2[MAX][MAX], dp3[MAX][MAX], dp4[MAX][MAX], ans;

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("%I64d", &a[i][j]);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            dp1[i][j] = a[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
    for(int i = n; i >= 1; i--)
        for(int j = 1; j <= m; j++)
            dp2[i][j] = a[i][j] + max(dp2[i + 1][j], dp2[i][j - 1]);
    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 = m; j >= 1; j--)
            dp4[i][j] = a[i][j] + max(dp4[i + 1][j], dp4[i][j + 1]);
    for(int i = 2; i < n; i++)
    {
        for(int j = 2; j < m; j++)
        {
            ans = max(ans, dp1[i - 1][j] + dp4[i + 1][j] + dp2[i][j - 1] + dp3[i][j + 1]);
            ans = max(ans, dp1[i][j - 1] + dp4[i][j + 1] + dp2[i + 1][j] + dp3[i - 1][j]);
        }
    }
    printf("%I64d\n", ans);
}


OpenMM | PDBFixer 用于蛋白质预处理 PDBFixer 用于蛋白质预处理 阅读详情

相关推荐

特征选择(模型输入参数的分析选择)方法汇总

特征选择是模式识别和机器学习领域的重要研究课题之一。为了提高准确率, 人们往往最大限度地提取特征信息。然而, 过大的特征向量维数不仅导致计算成本的增加, 复杂运算也随之带来分类识别率的下降。因此, 通过合适的特征选择算法, 去除无关特征和冗余特征, 获得有助于分类的最优特征子集, 对提高识别性能和降低计算成本具有重要意义。 特征选择主要有两个功能: 减少特征数量、降维,使模型泛化能力更强,减少过拟合 增强对特征和特征值之间的理解 参考资料: 优快云《几种常用的特征选择方法》 知乎《机器学习中,.

David's Tweet 1万+

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

别再死记硬背公式了!用Unity ShaderGraph从零实现一个皮肤SSS效果(附完整节点图)

本文详细介绍了如何利用Unity ShaderGraph零代码实现皮肤次表面散射(SSS)效果,包括背光透射(BTDF)和表面散射(BSSRDF)的核心原理与节点构建方法。通过可视化工具,技术美术师和Shader初学者可以直观理解光线在皮肤组织中的散射行为,快速创建真实的皮肤材质效果,适用于游戏角色渲染等场景。

weixin_30838873的博客 590

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

LangChain Message 官方文档

消息是聊天模型中的基本通信单位。它们用于表示聊天模型的输入和输出,以及与对话相关的其他上下文或元数据。每条消息都包含一个角色(如“用户”、“助手”)和内容(如文本或多模态数据),并可能包含根据不同聊天模型提供商而有所不同的附加元数据。LangChain 提供了一个统一的消息格式,可以跨不同聊天模型使用,简化用户在不同模型之间切换时所需关注的消息格式差异。

AI Agent 首席体验官 896

H3C IPsec over GRE VPN 实验

配置 IPsec over GRE VPN 来连通两端内网

M建的博客 2454

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

深入解析 TDA4VM/VH R5F 核中断机制:VIC 与非 VIC 模式下的实战对比与优化

本文深入解析了TI TDA4VM/VH平台中ARMv7-R架构R5F核的两种中断处理机制:VIC模式与非VIC模式。通过对比硬件自动跳转与软件向量表分发的核心流程、实战代码示例及性能差异,为开发者提供了基于实时性、灵活性与调试需求的选择指南和优化建议,帮助构建更稳定的嵌入式系统。

weixin_29159441的博客 97

四角递推(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

支持向量机算法之鸢尾花特征分类【机器学习】

支持向量机(SVM)是一种二元分类模型。它的基本模型是在特征空间中定义最大区间的线性分类器,这使它不同于感知器;支持向量机还包括核技术,这使得它本质上是一个非线性分类器。支持向量机的学习策略是区间最大化,它可以形式化为求解凸二次规划的问题,等价于正则化铰链损失函数的最小化。支持向量机的学习算法是求解凸二次规划的优化算法。Scikit learn(sklearn)是机器学习中常见的第三方模块。它封装了常见的机器学习方法,包括回归、降维、分类、聚类等。实例的特征向量(以2D为例)映射到空间中的一些点,如下图中的

一键难忘的博客 4970

Windows部署小龙虾 OpenClaw 报错不断?参考这篇文章,轻松配置 OpenClaw 所需环境

想在Windows上部署OpenClaw却频频报错?🔧 本文详细梳理了OpenClaw部署必需环境的安装步骤和官方下载地址 📦,提供完整的验证清单和常见问题排查方法,帮你一次性搞定所有环境配置,顺利部署OpenClaw ✅

XiaoqiangClub的博客 361

Codeforces 430D "Working out"——动态规划

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 ...

连长少尉 377

基于Linux的PCIe设备驱动开发入门到精通-- 11.2 锁机制与并发控制 (自旋锁、互斥锁) 11.3 性能瓶颈分析与优化建议

本文探讨Linux驱动开发中的性能优化方法论,重点聚焦并发控制与性能瓶颈分析。从锁机制选择(自旋锁、互斥锁等)到工具使用(ftrace、perf),详细介绍了定位锁竞争和CPU热点的实战步骤,包括ftrace事件跟踪和perf火焰图分析。针对常见性能瓶颈(CPU/内存/I/O/锁竞争),提出了锁粒度优化、无锁结构替换、中断处理优化等解决方案。强调性能优化需要理论结合实践,通过"假设-测量-验证"的循环持续迭代。为开发者提供了一套从问题定位到解决的完整方法论,助力开发高性能工业级驱动。

MHD0815的博客 125

2022.12.9-CodeForces429B-Working out

的最大权值和,但是无法保证去掉一个交点的权值和是最大的,所以我们只能选择从更优的解决方案,即:左上角到交点,右上角到交点,右下角到交点,左下角到交点这样算到的值才是最优的如下图。找出两条路径,在满足上述要求的情况下,使得路径经过的点除交点外的权值之和尽量大,输出这一最大值。最后的答案我们可以看到上下左右,但上既可能是从左上角来的也可能是从右上角来的所以要分别更新。首先我们模拟一个假设该路线就是最优解如下图。这样算到的可以证明的是我们最后的总和满足。这样我们去写这道题按正常的思路,更新。

weixin_62802134的博客 798

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

B. Working out CodeForces - 429B (动态规划)

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 mcolumns. Let number a...

SEVENY_的博客 282

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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][j] represen...

小雪花的博客 491

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

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

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

Code_KK的博客 1989

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

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

CodeForces 429B Working out 递推

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

canghai_wangzi的博客 361

Working out(DP 四个角递推)

B. Working outtime limit per test2 secondsmemory limit per test256 megabytesSummer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym ...

残阳止水 446

CodeForces429B WorkingOut

使用动态规划求解,思想还是很简单的,lahub只能向右和向下,lahubina只能向右和向上,限制条件就是只能相遇一次。 分析一下就能知道除边界点外其他所有点都有可能成为相遇点,对相遇点进行分析,要使满足只相遇一次的条件,只能有以下两种情况:lahub向下走到相遇点并继续向下走,此时lahubina向右走到相遇点并继续向右走;另外一种情况就是lahub向右走到相遇点并继续向右走,lahu

blueskyliulan的专栏 790

滚球游戏(数字三角形的变形)

问题 F: 滚球游戏 [命题人 : admin] 时间限制 : 1.000 sec 内存限制 : 128 MB 题目描述 某滚球游戏规则如下:球从入口处(第一层)开始向下滚动,每次可向下滚动一层,直到滚至最下面一层为止。球每次可滚至左下、下方或右下三个方格中的任意一个,每个方格都有一个得分,如样例所示。第1层有1个方格,第2层有3个方格,……,以此类推,第n层有2n-1个方格。设计一个算法,使得球从入口滚至最下面一层的总得分和最大。 输入 对于每个样例,第1行的正整数n表示数字三角形的行数。(n<=

weixin_53488675的博客 1178

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

Codeforces 429B Working out

Iahub只能向右或下走

xlp的acm专栏 1036

CodeForces429B Working out

Description 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]

Megumin的博客 950
上一篇: Codeforces 431C k-Tree (基础dp)
下一篇: UVA 12338 Anti-Rhyme Pairs (字符串哈希+二分)
_TCgogogo_
博客等级 码龄12年 615粉丝 1081原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值