Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import copy
  2.  
  3. def go(field, N, M, startx, starty, dx, dy):
  4. if startx+dx<0 or startx+dx>=N:
  5. return 0
  6. if starty+dy<0 or starty+dy>=M:
  7. return 0
  8. if field[startx, starty]==1:
  9. return 0
  10. newfield=copy.copy(field)
  11. newfield[startx, starty]=1
  12. startx=startx+dx
  13. starty=starty+dy
  14. if startx>=N-2 and starty>=M-2:
  15. return 1
  16. count=go(newfield, N, M, startx, starty, 2, 1)
  17. count=count+go(newfield, N, M, startx, starty, 2, -1)
  18. count=count+go(newfield, N, M, startx, starty, 1, 2)
  19. count=count+go(newfield, N, M, startx, starty, 1, -2)
  20. count=count+go(newfield, N, M, startx, starty, -2, 1)
  21. count=count+go(newfield, N, M, startx, starty, -2, -1)
  22. count=count+go(newfield, N, M, startx, starty, -1, 2)
  23. count=count+go(newfield, N, M, startx, starty, -1, -2)
  24. return count
  25.  
  26. def main():
  27. field={}
  28. N=int(raw_input("Enter N: "))
  29. M=int(raw_input("Enter M: "))
  30. for i in range(0, N):
  31. for j in range(0, M):
  32. field[i, j]=0
  33. count=go(field, N, M, 1, 1, 2, 1)
  34. count=count+go(field, N, M, 1, 1, 2, -1)
  35. count=count+go(field, N, M, 1, 1, 1, 2)
  36. count=count+go(field, N, M, 1, 1, 1, -2)
  37. count=count+go(field, N, M, 1, 1, -2, 1)
  38. count=count+go(field, N, M, 1, 1, -2, -1)
  39. count=count+go(field, N, M, 1, 1, -1, 2)
  40. count=count+go(field, N, M, 1, 1, -1, -2)
  41. print count
  42.  
  43. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement