如何找到从源到目的地的路径数,它在2d矩阵中加到给定的和k?(How to find the number of path from source to destination which adds upto to a given sum k in a 2d matrix?)

270 IT屋

In NxN matrix containing numbers and block ''x''.find the number of path from the source ''s'' to destination ''d'' which adds upto given sum ''k''. Use Dynamic programming to solve this.Move in down ,right and diagonal direction.

input:
--------------
k = 3

s 1 1
1 x 1
1 1 d

output = 2
--------------
k = 5

e 1 1 1

1 1 1 1

1 1 1 1

1 1 1 s

output = 20
-------------

k = 7

e 2 3

2 x 2

1 2 s

output = 1
-------------

What I have tried:

I have tried using recursion, as it will take more time complexity.

解决方案
We are more than willing to help those that are stuck: but that doesn''t mean that we are here to do it all for you! We can''t do all the work, you are either getting paid for this, or it''s part of your grades and it wouldn''t be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn''t mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Quote:
How to find the number of path from source to destination which adds upto to a given sum k in a 2d matrix?

This look like some homework, but your main effort is pasting the requirement.
What is the question?
Quote:
Use Dynamic programming to solve this.

You are given hint about how to do.

We are not doing your homework, if you want help, you need to show your work and explain problem.

To get you started, you can start with a brute force approach (trying every path 1 by 1), then refine.

在包含数字和块x的NxN矩阵中。找到从源s到目的地d的路径数,它加到给定的总和k。使用动态编程来解决这个问题。向下,向右和向对角方向移动。



输入:

-------- ------

k = 3



s 1 1

1 x 1

1 1 d



输出= 2

--------------

k = 5


$ b $是1 1 1



1 1 1 1



1 1 1 1



1 1 1 s



输出= 20

-------------



k = 7



e 2 3



2 x 2



1 2 s



输出= 1

-------------



我尝试了什么:



我尝试过使用递归,因为它需要更多的时间复杂度。

解决方案
我们非常愿意帮助那些陷入困境的人:但这并不意味着我们在这里为你们所做的一切!我们不能做所有的工作,你要么得到报酬,要么就是你成绩的一部分,我们为你做这一切都不公平。



所以我们需要你做的工作,我们会在你遇到困难时帮助你。这并不意味着我们会为您提供一步一步的解决方案!

首先解释您目前的位置,以及该流程的下一步是什么。然后告诉我们你试图让下一步工作,以及你做了什么。

Quote:
如何找到从源到目的地的路径数,它在2d矩阵中加到给定的总和?


这看起来像是一些功课,但你的主要努力粘贴要求。

有什么问题?

引用:
使用动态编程来解决这个问题。


你会得到关于如何做的提示。



我们不做你的功课,如果你需要帮助,你需要展示你的工作并解释问题。



为了让你开始,你可以从蛮力的方法开始(尝试每条路径1乘1 ),然后改进。

本文地址:IT屋 » 如何找到从源到目的地的路径数,它在2d矩阵中加到给定的和k?