SPOJ — DOMINOES Getting WA Please Help!!

Revision en1, by anm_coder007, 2019-11-02 15:18:34

I am getting WA for the problem DOMINOES. But I can't seem to figure anything wrong in my approach. My approach is as follows :
- Sort the dominoes from left to right on 'x'.
- For every Domino, calculate the last domino to the left which will falls if i push this domino to the left(max_left[i])
- For every Domino, calculate the first domino to its left such that when it falls to the right also makes this domino fall to the right(min_right[i])
- Recurrence Relation :
dp[i][L] = max_left[i] == 0 ? 1 : (1 + min(dp[max_left[i] — 1][L], dp[max_left[i] — 1][R]))
dp[i][R] = 1 + min(dp[i-1][L], dp[i-1][R]);
dp[i][R] = min_right[i] == 0 ? 1 : min(dp[i][R], dp[min_right[i]][R]);
answer is min(dp[n-1][L], dp[n-1][R]);

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English anm_coder007 2019-11-02 15:18:34 912 Initial revision (published)