• recategorized ago by
33 views
0 0 votes

CMI 2026 | CS | Part C | Question-8

In the Pots-of-Gold game, there is a row of $n$ pots $P_{1}, \ldots, P_{n}$. Each pot contains some number of gold coins. You remove pots and collect the gold coins from the pots that you remove, subject to the rules below. Your aim is to collect as many gold coins as possible.

  • You start with no gold coins and remove pots one at a time. You can remove any pot that is available for removal.
  • In the beginning, all pots are available for removal. Removing pot $P_{i}$ makes the pots $P_{i-1}$ and $P_{i+1}$ (if they exist) permanently unavailable.
  1. Assuming that we have an array $G[1 \ldots n]$ with $G[i]$ storing the number of gold coins in pot $P_{i}$, devise an algorithm $\operatorname{PotsOfGold}(G, n)$ that computes the maximum number of gold coins that you can collect. Your algorithm should run in $O(n)$ time in the worst case. You can assume that each arithmetic operation involving two integers, and each array access (reading/writing one element) takes constant time. Hint: Use dynamic programming.
  2. Clearly explain why your procedure of part (a) correctly computes the required output.
  3. Explain why your procedure of part (a) runs in $O(n)$ time in the worst case.

Please log in or register to answer this question.

Position:
Show:

Related questions

0 0 votes
0 0 answers
39
39 views
Shubham Sharma 2 asked Aug 23
39 views
You are given a graph on vertex set $V=\{a_{1}, \ldots, a_{k}\} \cup\{b_{1}, \ldots, b_{k}\}$. The edge set is $E=\{(a_{i}, b_{j}) \mid. i \neq j\}$. An edge coloring of ...
1 1 vote
1 1 answer
670
670 views
soujanyareddy13 asked Jan 9, 2022
670 views
Given the following characteristics :Optimal substructureOverlapping subproblemsMemorizationDecrease and conquerDynamic programming has the following characteristics :$\t...
1 1 vote
2 2 answers
515
515 views
Shubham Sharma 2 asked Sep 10, 2025
515 views
The longest common subsequence of $\{1,2,3,2,4,1,2\}$ and $\{2,4,3,1,2,1\}$ is$2,1,2,3$$1,3,2,1$$2,3,2,1$$2,3,1,2,1$
0 0 votes
1 1 answer
498
498 views
Shubham Sharma 2 asked Sep 9, 2025
498 views
Arrange the following steps in the correct order to solve the Knapsack problem using Dynamic Programming.Define the base case when the capacity is zero ($0$) or no items ...