如何找到从源到目的地的路径数,该路径数加起来等于二维矩阵中的给定总和k? [英] How to find the number of path from source to destination which adds upto to a given sum k in a 2d matrix?

查看:504
本文介绍了如何找到从源到目的地的路径数,该路径数加起来等于二维矩阵中的给定总和k?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在包含数字和块``x''的NxN矩阵中,找到从源``s''到目标``d''的路径数,该路径数加起来等于给定的总和``k''.使用动态编程来解决此问题.向下,向右和对角线方向移动.

输入:
--------------
k = 3

s 1 1
1 x 1
1 1 d

输出= 2
--------------
k = 5

e 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
-------------

我尝试过的事情:

我尝试使用递归,因为它将花费更多的时间.

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.


报价:

如何找到从源到目的地的路径数,该路径数加起来等于二维矩阵中的给定总和k?

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?

报价:

使用动态编程来解决这个问题.

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.


这篇关于如何找到从源到目的地的路径数,该路径数加起来等于二维矩阵中的给定总和k?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆