Friday, 25 November 2016

MCOINS - Coins Game - Solution

MCOINS - Coins Game is an easy bottom-up DP problem.

I am assuming that you have already understood the problem statement, otherwise go back and read the problem statement again.

In this problem, we have made an array b[] which contains height of different towers, and we have to print a string containing A and B, who's ith element represent the player who will win for the ith tower. Now we have to print A if first player wins and B if second player wins.

Now, we have an array a[], which contains result of all towers.

Each player can choose 1,K or L to remove from tower, so if there is a tower with height 1, first player will win. So, we keep a[1] = 1

Now, for every i, A can win only if
a[i-1] = 0 or a[i-K] = 0 or a[i-L] = 0

otherwise B will win.

I hope you can implement the code for this problem yourself otherwise refer to the following code:

0 comments:

Post a Comment