Skip to content

Instantly share code, notes, and snippets.

@MinecraftFuns
Created July 22, 2020 01:20
Show Gist options
  • Save MinecraftFuns/2bdcf46f8cf19801f6ffefa284f34ff8 to your computer and use it in GitHub Desktop.
Save MinecraftFuns/2bdcf46f8cf19801f6ffefa284f34ff8 to your computer and use it in GitHub Desktop.
import random
a = [[0 for _ in range(105)] for __ in range(105)]
x, y = 1, 1
for contain in range(1, 1001):
a[x][y] = contain
if x == 1:
x = y + 1
y = 1
else:
x -= 1
y += 1
def func(q, w, e, r):
res = set()
def dfs(x, y, ans):
ans += a[x][y]
if x == e and y == r:
res.add(ans)
elif x == e:
dfs(x, y + 1, ans)
elif y == r:
dfs(x+1, y, ans)
else:
dfs(x + 1, y, ans)
dfs(x, y + 1, ans)
dfs(q, w, 0)
return len(res)
for _ in range(50):
q, w = random.randint(1, 10), random.randint(1, 10)
e, r = q + random.randint(1, 10), w + random.randint(1, 10)
print(q, w, e, r)
print(func(q, w, e, r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment