面试算法题 《最长路径》

tommake 2013-03-18 11:15:12
You are given a 2D grid of integers. You have to find the longest path in the grid such that adjacent terms in the path have a difference of +1/-1. Print all paths of max length. Constraint : you can move only down and right.

大概意思是 给定一个整数二维数组 n X n,找出 其中的最长路径,每个相邻的整数差为+1/-1. 条件:你只能往右边或者下方移动。
...全文
287 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dracularking 2013-03-20
  • 打赏
  • 举报
回复
这个可以用广搜或深搜啊 向右或向下行进条件是相邻节点是否相差+/-1 每当回溯时,记录下回溯点 等搜完在所有结果集中找最优
superchair 2013-03-20
  • 打赏
  • 举报
回复
如果没看错题... a[x,y]=a[x,y]+(a[x,y-1]>a[x-1,y]?a[x,y-1]:a[x-1,y]); 然后输出a[n,n]就是了
冰思雨 2013-03-18
  • 打赏
  • 举报
回复
用函数的递归调用,求出所以可能性,找到合乎要求的路径。这是笨办法。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧