Created
February 14, 2020 15:52
-
-
Save wheeliechamp/784a13f48cbc969121d9b3105fa7709d to your computer and use it in GitHub Desktop.
Python 再帰処理
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
# これもだめだった | |
#8 300 400 | |
#9 39 | |
#48 38 | |
#21 10 | |
#14 45 | |
#32 20 | |
#32 48 | |
#9 7 | |
#19 16 | |
data = [] | |
info = list(map(int, input().split(' '))) | |
for i in range(info[0]): | |
tmp = input().rstrip().split(' ') | |
data.append(tmp) | |
n = int(info[0]) | |
base = int(info[1]) | |
danger = int(info[2]) | |
result = [] | |
def func(base, i, result): | |
if i > n-1: | |
return | |
base_m = base - int(data[i][0]) | |
if base_m > 0 and base_m <= danger: | |
if i == n-1: | |
result.append(base_m) | |
func(base_m, i+1, result) | |
else: | |
print("Else") | |
base_p = base + int(data[i][1]) | |
if base_p > 0 and base_p <= danger: | |
if i == n-1: | |
result.append(base_p) | |
func(base_p, i+1, result) | |
func(base, 0, result) | |
print(len(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment