当前位置:网站首页>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代码:
边栏推荐
- This error is reported when the shake database is started. Is there a problem with the configuration?
- flask基础知识:
- 2021年9月电子学会图形化二级编程题解析含答案:帮小企鹅躲避暴风雪
- Performance optimization | CPU power management from the perspective of ping delay
- HCIP第十三天作业——综合实验
- 2021年9月电子学会图形化一级编程题解析含答案:无奈的Jaime
- 水印图像读取与制作,三通道图转为4通道,制作透明图
- 一些小题22.08.07
- 啥?分库分表会带来读扩散问题?怎么解决???
- ABAP 报表中如何给报表的输入参数增添 F4 Value Help 试读版
猜你喜欢
随机推荐
APICloud AVM 封装日期和时间选择组件
干货技巧|如何用3DsMax制作笔记本电脑
轻量全景查看器 pannellum初探
A Preliminary Study on Pannellum, a Lightweight Panorama Viewer
第4讲:SQL语句之DDL类型的数据库定义语言
16. Learn Lua file I/O together
Redis Server启动过程
PX4模块设计之十九:Replay模块
达梦数据库 DmAPservice服务,启停影响 DMSERVER库服务吗?
21天学习挑战赛——机器学习03
hdu1042 N! (large number)
内核实战教程第1期|数据库系统概述,带你走近 OceanBase 研发环境!
看三年的CRUD程序员如何解决数据库死锁的
2021年9月电子学会图形化三级编程题解析含答案:接红包游戏
视图,索引
全栈开发可能需要的环境及工具
ABAP 报表中如何给报表的输入参数增添 F4 Value Help 试读版
Style Design Principles in Open Office XML Format
什么是Shell?从小白到入门你只差一个它
【wpf】Bingding的方向和触发的时机









