Embercode
✕
Dynamic ProgrammingQuick quiz

Egg drop and DAG DP

8 questions. Covers Longest path in a DAG by topological DP.

Questions 1 to 5 of 8

  1. 1. Which statements about the moves table reach[k][m] in the egg drop lesson are true? Pick all that apply.

    Pick every answer that is true.

  2. 2. What does this program print? ``cpp #include <iostream> #include <vector> int main() { std::vector<long long> reach(3, 0); for (int move = 1; move <= 3; ++move) { for (int k = 2; k >= 1; --k) { reach[k] = reach[k - 1] + reach[k] + 1; } } std::cout << reach[1] << ' ' << reach[2] << '\n'; } ``
  3. 3. Why does fewest_drops_by_moves update the eggs from eggs down to 1?
  4. 4. The lesson builds a topological order with a queue and in-degrees. Which person's name is given to that method? Write the surname only.

    Type your answer.

  5. 5. What does this program print? ``cpp #include <iostream> #include <vector> struct Edge { int from; int to; int weight; }; int main() { constexpr long long kNoPath = -1000; const std::vector<Edge> edges = {{0, 1, 2}, {0, 2, 5}, {1, 2, 1}, {1, 4, 5}, {2, 3, 2}, {3, 4, 1}}; std::vector<long long> dist(5, kNoPath); std::vector<int> parent(5, -1); dist[0] = 0; for (const Edge& e : edges) { if (dist[e.from] == kNoPath) { continue; } const long long candidate = dist[e.from] + e.weight; if (candidate > dist[e.to]) { dist[e.to] = candidate; parent[e.to] = e.from; } } std::cout << dist[4] << ' ' << parent[4] << '\n'; } ``

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.