Deciding the state

Dynamic Programming problems are all about the state and its transition. This is the most basic step which must be done very carefully because the state transition depends on the choice of state definition you make.

State:

A state can be defined as the set of parameters that can uniquely identify a certain position or standing in the given problem. This set of parameters should be as small as possible to reduce state space. 

Example:

In our famous Knapsack problem, we define our state by two parameters index and weight i.e DP[index][weight]. Here DP[index][weight] tells us the maximum profit it can make by taking items from range 0 to index having the capacity of sack to be weight. Therefore, here the parameters index and weight together can uniquely identify a subproblem for the knapsack problem.

The first step to solving a Dynamic Programming problem will be deciding on a state for the problem after identifying that the problem is a Dynamic Programming problem. As we know Dynamic Programming is all about using calculated results to formulate the final result. 
So, our next step will be to find a relation between previous states to reach the current state

Steps for how to solve a Dynamic Programming Problem

Similar Reads

Steps to solve a Dynamic programming problem:

Identify if it is a Dynamic programming problem. Decide a state expression with the Least parameters. Formulate state and transition relationship. Apply tabulation or memorization....

Step 1: How to classify a problem as a Dynamic Programming Problem?

Typically, all the problems that require maximizing or minimizing certain quantities or counting problems that say to count the arrangements under certain conditions or certain probability problems can be solved by using Dynamic Programming. All dynamic programming problems satisfy the overlapping subproblems property and most of the classic Dynamic  programming problems also satisfy the optimal substructure property. Once we observe these properties in a given problem be sure that it can be solved using Dynamic Programming....

Step 2: Deciding the state

Dynamic Programming problems are all about the state and its transition. This is the most basic step which must be done very carefully because the state transition depends on the choice of state definition you make....

Step 3: Formulating a relation among the states

This part is the hardest part of solving a Dynamic Programming problem and requires a lot of intuition, observation, and practice....

Step 4: Adding memoization or tabulation for the state

...

Contact Us