-
-
Save MinecraftFuns/2bdcf46f8cf19801f6ffefa284f34ff8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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