|
|
back to boardDynamic solution - help needed I want to use bool dp[N][N][3] array, where dp[i][j][0] is true if it is possible to solve the problem for last 'i' characters of string1 and for last 'j' characters of string2 and in current state it is necessary to take 0 and place into the stack of '0's. dp[i][j][1] is true if it is possible to solve the problem for last 'i' characters of string1 and for last 'j' characters of string2 and in current state it is necessary to take 1 and place into the stack of '1's. dp[i][j][2] is true if it is possible to solve the problem for last 'i' characters of string1 and for last 'j' characters of string2 and in current state stacks of '0's and '1's have the same size. Obviously (dp[N][N][2] == true) means that it is possible to solve the problem. My problem is that I can't fill this 3D array. Please help. Re: Dynamic solution - help needed Posted by HM2P33 22 Oct 2014 05:32 you just need dp[i][j] and store there form were you get the last piece, if it was from 1 you can rebuild the path looking dp[i-1][j], if it was from 2 you llok dp[i][j-1]. If dp[i][j] = 0 you can't solve the problem. |
|
|