当前位置:网站首页>nyoj 712 Exploring treasure
nyoj 712 Exploring treasure
2022-08-08 18:57:00 【51CTO】
探 寻 宝 藏
1000 ms | 内存限制: 65535
5
传说HMH大沙漠中有一个M*N迷宫,里面藏有许多宝物.某天,Dr.Kong找到了迷宫的地图,他发现迷宫内处处有宝物,最珍贵的宝物就藏在右下角,迷宫的进出口在左上角.当然,Pathways in a maze are not flat,到处都是陷阱.Dr.KongDecided to let his robot Kado go on an expedition.
But when the robot cardo goes from the upper left corner to the lower right corner,Only go down or to the right.When going back from the lower right corner to the upper left corner,Only go up or to the left,And Cardo isn't going back.(即:一个点最多经过一次).Of course, Cardo also took every treasure along the way.
Dr.KongI hope his robot Kaduo can bring out as many treasures as possible.请你编写程序,帮助Dr.Kong计算一下,How many treasures can Cardo bring out at most.
第一行: K 表示有多少组测试数据.
Next, test data for each set:
第1行: M N
第2~M+1行: Ai1 Ai2 ……AiN (i=1,…..,m)
【约束条件】
2≤k≤5 1≤M, N≤50 0≤Aij≤100 (i=1,….,M; j=1,…,N)
All data are integers. 数据之间有一个空格.
输出 对于每组测试数据,输出一行:Robot Cardo carries the most valuable treasures 样例输入
样例输出
来源 第六届河南省程序设计大赛
上传者 ACM_赵铭浩
This question is the same as what we have done in the pastdp不同之处就在于 go and go
Join only go 我们可以 Use dynamic programming equations dp[i][j]=max(dp[i-1][j],dp[i][j-1])+map[i][j].
And this question went and came back We can understand that two people go from the upper left corner at the same time But don't go the same way
If two people don't go the same way Then the two people must not be in the same column or row 又因为 Both people take the exact same number of steps
So we can get the number of steps taken by another person through the number of steps taken by one person
We can store it through a four-dimensional array
So this time the dynamic programming equation
附上代码:
Because the space occupied by the four-dimensional array is particularly large And because in this question two people take exactly the same number of steps 也就是i+j=k+l So we can pass the step count 转换为3维的
dp[k][i][j] 其中kis the current number of steps taken ito the left of the row for the first person jis the row coordinate of the second person
And because the coordinates of the upper left corner of the map I created are (1,1) So the minimum number of steps required to go from the upper left corner to the lower right corner is m+n-2
The dynamic transition equation at this time is
ac代码:
边栏推荐
猜你喜欢
携手华为打造鲲鹏产业生态 | 麒麟信安亮相鲲鹏开发者创享日·长沙站
TensorFlow学习记录(七):生成对抗网络
阿里云数据库PolarDB开源人才培养计划发布!万元好礼等你来拿!
Style Design Principles in Open Office XML Format
MogDB study notes - starting from 0
Vue program of web cache problem after packaging
openEuler 社区 2022 年 7 月运作报告
搭建企业级数据治理体系指南
Architecture Design Fundamentals
2021年9月电子学会图形化三级编程题解析含答案:接红包游戏
随机推荐
搭建DG导致归档日志量变多问题排查
2021年9月电子学会图形化三级编程题解析含答案:计算平均分
Go-Excelize API源码阅读(四)——Save()
性能问题从发现到优化一般思路
ptorch
PX4模块设计之十九:Replay模块
torchvision.transforms
ADB安装方法:
内核实战教程第1期|数据库系统概述,带你走近 OceanBase 研发环境!
Redhat 7 Maria DB installation and configuration
3D角色建模师和3D角色动画师哪个更有前景?哪个更适合小白入门?
精彩来袭!鲲鹏开发者创享日·长沙站来啦
Laravel 队列消费实例和定时任务添加任务消费
干货技巧|如何用3DsMax制作笔记本电脑
元宇宙三巨头Animoca Brands、Yuga Labs、Gala多维度对比,谁才是未来?
水印图像读取与制作,三通道图转为4通道,制作透明图
TensorFlow学习记录(七):生成对抗网络
SSH协议抓包-工具Wireshark
APICloud AVM wraps date and time selection components
Fortinet new cloud native protection products launched amazon cloud platform of science and technology