Skip to content

Instantly share code, notes, and snippets.

@tchomphoochan
Last active January 28, 2019 13:01
Show Gist options
  • Save tchomphoochan/b0aa3be83a83db8b289598907f8ff45a to your computer and use it in GitHub Desktop.
Save tchomphoochan/b0aa3be83a83db8b289598907f8ff45a to your computer and use it in GitHub Desktop.
char A[MAX_N][MAX_M]; // assume the board's data is in A[1..n][1..m]
int dp[MAX_N][MAX_M]; // set everything to 0 (so dp[0][0..m] and dp[0..n][0] will be 0)
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (A[i][j] == '#')
dp[i][j] = 0;
else if (i == 1 && j == 1)
dp[i][j] = 1;
else
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
// according to the above example:
// cout << dp[5][4] << endl;
// result = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment