Correct Path

本文介绍了Correct Path算法,这是一个涉及到5x5棋盘格的路径寻找问题。从左上角(1,1)出发,目标是到达右下角(5,5),路径包括'r'(右移),'l'(左移),'d'(下移),'u'(上移)和'?'(未知方向)。算法要求不能经过已走过的格子,对于'?',起始点和终点有2种选择,其他位置有4种选择。作者提出通过遍历所有可能的路径来找到符合条件的解决方案。" 108281532,10039164,分布式系统中的雪花算法:Twitter的全局唯一ID生成策略,"['分布式计算', '数据库', '算法', '分布式系统']
摘要由CSDN通过智能技术生成

Challenge

Using the C# language, have the function  CorrectPath(str) read the  str parameter being passed, which will represent the movements made in a 5x5 grid of cells starting from the top left position. The characters in the input string will be entirely composed of:  r, l, u, d, ?. Each of the characters stand for the direction to take within the grid, for example: r = right, l = left, u = up, d = down. Your goal is to determine what characters the question marks should be in order for a path to be created to go from the top left of the grid all the way to the bottom right without touching previously travelled on cells in the grid. 

For example: if  str is "r?d?drdd" then your program should output the final correct string that will allow a path to be formed from the top left of a 5x5 grid to the bottom right. For this input, your program should therefore return the string  rrdrdrdd. There will only ever be one correct path and there will always be at least one question mark within the input string. 
Sample Test Cases

Input:"???rrurdr?"

Output:"dddrrurdrd"


Input:"drdr??rrddd?"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值