====== 모노디지털 표현 ====== ===== 풀이 ===== * [[ps:problems:programmers:42895]]와 같은 문제. 풀이는 그쪽 참고. 코드는 조금 더 다듬었다. ===== 코드 ===== """Solution code for "BOJ 2287. 모노디지털 표현". - Problem link: https://www.acmicpc.net/problem/2287 - Solution link: http://www.teferi.net/ps/problems/boj/2287 """ import sys MAX = 8 def main(): K = sys.stdin.readline().rstrip() dp = [] for i in range(1, MAX + 1): dp_new = {int(K * i)} for dp1, dp2 in zip(dp, reversed(dp)): for n1 in dp1: for n2 in dp2: dp_new.update((n1 + n2, n1 - n2, n1 * n2)) if n2 != 0: dp_new.add(n1 // n2) dp.append(dp_new) n = int(sys.stdin.readline()) for _ in range(n): a = int(sys.stdin.readline()) try: print(next(i + 1 for i, dp_i in enumerate(dp) if a in dp_i)) except StopIteration: print('NO') if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:골드_2}}