-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Adding dynamic programming solution for unique paths problem #2992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
a73323e
ba22f9f
d87ca7c
8dce8c6
548c500
1a71f3b
eb39769
5e5b2cd
35fe129
d7f9c60
df740a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||
/** | ||||||
* @file | ||||||
* @brief Implementation of Unique Paths problem using | ||||||
* Dynamic Programming (Memoization + Tabulation). | ||||||
* @details | ||||||
* A robot is located at the top-left corner of an m x n grid. | ||||||
* The robot can move either down or right at any point in time. | ||||||
realstealthninja marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* The robot is trying to reach the bottom-right corner. | ||||||
* This program computes the total number of unique paths. | ||||||
* | ||||||
* @see https://leetcode.com/problems/unique-paths/ | ||||||
*/ | ||||||
|
||||||
#include <iostream> | ||||||
#include <vector> | ||||||
#include <cassert> | ||||||
using namespace std; | ||||||
|
using namespace std; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace dp { | |
namespace dynamic_programming { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is bad design, the user should not have to worry about supplying a memoization table, This is design details that should be handled internally
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dp[i][j] = solveMem(i + 1, j, m, n, dp) + solveMem(i, j + 1, m, n, dp); | |
dp.at(i).at(j) = solveMem(i + 1, j, m, n, dp) + solveMem(i, j + 1, m, n, dp); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be turned into a class? with a private member of dp, and multiple behaviours, solvetabular() or solvememoised()
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests only test the tabular form and not the memoized form
Uh oh!
There was an error while loading. Please reload this page.