CLASS ASSIGNMENT giving TLE

TLE
question = https://hack.codingblocks.com/contests/c/452/875
solution = https://ide.codingblocks.com/#/s/21324

Bro try to make a relation in between the terms . Relation such as recursive relation or try to make a dp relation