In the given ex. when n=4
- piyush pics 4
2… nimit can pick either 1 or 3, if he picks 1 then piyush will 3 and the sum for piyush will go (4+3=7), which is maximum.
But the answer given as 6…why??
In the given ex. when n=4
hi @aryan, here both player will play optimally(Playing optimally means that both players will have insight into all possible next moves and will play in such a way to maximize their chance of winning without making a mistake.) so nimit will choose the coin that will result in less value left for piyush .
so coming to the giving example it means he has choice to choose between 1 and 3 so out of which he will choose the option which is good for him .
if he had chosen 1 then nimit would have 7 with him that’s why he choose 3 thus piyush getting 6 coins
In the question it is written that both will play optimally
what you mean is the greedy approach you have to think in terms of dynammic programming