Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- def go(field, N, M, startx, starty, dx, dy):
- if startx+dx<0 or startx+dx>=N:
- return 0
- if starty+dy<0 or starty+dy>=M:
- return 0
- if field[startx, starty]==1:
- return 0
- newfield=copy.copy(field)
- newfield[startx, starty]=1
- startx=startx+dx
- starty=starty+dy
- if startx>=N-2 and starty>=M-2:
- return 1
- count=go(newfield, N, M, startx, starty, 2, 1)
- count=count+go(newfield, N, M, startx, starty, 2, -1)
- count=count+go(newfield, N, M, startx, starty, 1, 2)
- count=count+go(newfield, N, M, startx, starty, 1, -2)
- count=count+go(newfield, N, M, startx, starty, -2, 1)
- count=count+go(newfield, N, M, startx, starty, -2, -1)
- count=count+go(newfield, N, M, startx, starty, -1, 2)
- count=count+go(newfield, N, M, startx, starty, -1, -2)
- return count
- def main():
- field={}
- N=int(raw_input("Enter N: "))
- M=int(raw_input("Enter M: "))
- for i in range(0, N):
- for j in range(0, M):
- field[i, j]=0
- count=go(field, N, M, 1, 1, 2, 1)
- count=count+go(field, N, M, 1, 1, 2, -1)
- count=count+go(field, N, M, 1, 1, 1, 2)
- count=count+go(field, N, M, 1, 1, 1, -2)
- count=count+go(field, N, M, 1, 1, -2, 1)
- count=count+go(field, N, M, 1, 1, -2, -1)
- count=count+go(field, N, M, 1, 1, -1, 2)
- count=count+go(field, N, M, 1, 1, -1, -2)
- print count
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement