Embercode
✕
Dynamic ProgrammingQuick quiz

Grid paths and triangles

7 questions. Covers Minimum path sum and triangle from the bottom.

Questions 1 to 5 of 7

  1. 1. A grid has 3 rows and 4 columns and no obstacles. Which expression gives the number of routes from the top-left cell to the bottom-right cell?
  2. 2. What does this program print? ``cpp #include <iostream> int main() { int grid[3][4] = { {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, }; long long ways[3][4] = {}; for (int r = 0; r < 3; ++r) for (int c = 0; c < 4; ++c) { if (grid[r][c] == 1) ways[r][c] = 0; else if (r == 0 && c == 0) ways[r][c] = 1; else ways[r][c] = (r > 0 ? ways[r - 1][c] : 0) + (c > 0 ? ways[r][c - 1] : 0); } std::cout << ways[2][3] << "\n"; } ``
  3. 3. Which statements about the one-row version of the grid table are true?

    Pick every answer that is true.

  4. 4. Why does the lesson say a table is needed once any cell is blocked?
  5. 5. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<std::vector<int>> t = {{1}, {8, 2}, {4, 9, 5}}; std::vector<int> best = t.back(); for (int r = static_cast<int>(t.size()) - 2; r >= 0; --r) for (int c = 0; c <= r; ++c) best[c] = t[r][c] + std::min(best[c], best[c + 1]); std::cout << best[0] << "\n"; } ``

5 question(s) left on this page.