当前位置:网站首页>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代码:
边栏推荐
- torchvision.transforms
- Style Design Principles in Open Office XML Format
- ADB安装方法:
- Why do programmers only close monitor from none computer after work?Look at the answer ~ each big web site
- APICloud AVM 封装日期和时间选择组件
- Redis Server启动过程
- Vue program of web cache problem after packaging
- Azure Neural TTS continues to be updated to help enterprises develop small language markets
- LabVIEW报错“仪器IO助手未正确安装”
- 01. Preface
猜你喜欢
/目录 、/home目录 、~目录的区别
openEuler资源利用率提升之道02:典型应用下的效果
2021年9月电子学会图形化二级编程题解析含答案:画正多边形
卡通渲染的历史
uniapp parent component uses prop to pass asynchronous data to child components
PG 之 huge page
Open Office XML 格式中的 Style 设计原理
Style Design Principles in Open Office XML Format
Task-Driven Super Resolution: Object Detection in Low-resolution Images
数据库学习之表的操作
随机推荐
架构设计基本原则
Go-Excelize API源码阅读(四)——Save()
CAD进阶练习(二)
面试官:Redis 大 key 要如何处理?
水印图像读取与制作,三通道图转为4通道,制作透明图
21天学习挑战赛——机器学习02
Geometric g6 will carry harmonyos system, a comprehensive upgrade competitiveness of products
请问在MAXCOMPUTE SQL 里有没有函数判断string 是否为数字?
How is the private key generated by OpenSSH used in putty?
关于求最小公倍数的三种常用方法
This error is reported when the shake database is started. Is there a problem with the configuration?
2021年9月电子学会图形化二级编程题解析含答案:画正多边形
BP神经网络
PG 之 huge page
使用 lua 运行 fscript
如何在Firewalld中为特定IP地址开放端口
Learn about layered architecture & SOA architecture together
Fortinet全新云原生保护产品上线亚马逊云科技平台
el-tree设置单选,点击完成后收起
性能优化|从ping延时看CPU电源管理