Блог пользователя code_warrior

Автор code_warrior, история, 4 года назад, По-английски

Recently ,I faced a question which says that given a square matrix of size n x n with entries only as 0 ans 1's ,we are required to count the number of unique paths from (1,1) to (n,n) if "0" means that the cell is safe and "1" means that there is an obstacle. We are allowed to move in four directions if possible that is from (X,Y), one can move to (X,Y+1), (X,Y-1),(X+1,Y) or (X-1,Y). Each cell can be visited at most once. I tried to solve it with dyanamic programming , but couldn't make my way to AC. One thing more, N<=20. Can anyone give me some hint how to solve this?

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

I just wanted to know what if N<=100000 and the obstacles are less than 3000. How do you solve the problem then? I knew there is a method to iterate only on the obstacles but I forgot that method. Can anyone help?