https://www.acmicpc.net/problem/1248
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | def check(aa): global n v3 = v[:] for i in range(n): for j in range(i, n): vv = v3.pop(0) if vv == '+': if sum(aa[i:j+1]) <= 0: return False elif vv == '-': if sum(aa[i:j + 1]) >= 0: return False elif vv == '0': if sum(aa[i:j + 1]) != 0: return False return True def recur(idx): global n, result if result: return if idx == n: if check(a): result = ' '.join(map(str, a)) return if s[idx][idx] == '0': a[idx] = 0 recur(idx + 1) elif s[idx][idx] == '+': for i in range(1,11): a[idx] = i recur(idx + 1) elif s[idx][idx] == '-': for i in range(-1,-11,-1): a[idx] = i recur(idx + 1) n = int(input()) v = list(input()) lst = list(range(-10, 11)) s = [[None]*n for _ in range(n)] a = [None]*n v2 = v[:] for i in range(n): for j in range(i,n): s[i][j] = v2.pop(0) result = '' recur(0) print(result) | cs |
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[Python]14502. 연구소 (0) | 2019.05.09 |
---|---|
[Python]12100. 2048 (Easy) (0) | 2019.05.08 |
[Python]14889. 스타트와 링크 (0) | 2019.04.22 |
[Python]17143. 낚시왕 (0) | 2019.04.18 |
[Python]2529. 부등호 (0) | 2019.04.16 |
댓글