Consider you have a screen. Now we can do two operations on the screen:
Copy content on the screen
Paste copied content on the screen
Suppose at the beginning, the clipboard is empty and there is one character on the screen. If we have N operations, how we can print the maximum number of characters on the screen using N operations of copy and pastes?
The answer is
DP[N]=max(2DP[N-2],3DP[N-3])
But how do we get the above result? And why below formulations aren't correct?
DP[N]=max(DP[N-1],2DP[N-2])DP[N]=2DP[N-2]