BAEKJOON : 14225, 16197
No. 14225
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline())
seq = list(map(int,sys.stdin.readline().rstrip().split()))
check_num = [False] * ((n*100000)+1)
for i in range(1,1<<n):
sum = 0
for j in range(20):
if i & (1<<j) == 0:
continue
else:
sum += seq[j]
check_num[sum] = True
for i in range(1,len(check_num)):
if check_num[i] == True:
continue
else:
print(i)
break
3. Others' solutions import sys
def dfs(idx,sum):
if sum > 0:
check_num[sum] = True
if idx >= n:
return
dfs(idx+1, sum)
dfs(idx+1, sum+seq[idx])
n = int(sys.stdin.readline())
seq = list(map(int,sys.stdin.readline().rstrip().split()))
check_num = [False] * ((n*100000)+1)
dfs(0,0)
for i in range(1,len(check_num)):
if check_num[i] == True:
continue
else:
print(i)
break
4. Learned No. 16197
1. Problem
2. Others' Solutions
2つの座標をキューに挿入し、2つの硬貨
import sys
from collections import deque
def bfs():
queue = deque()
queue.append(coin + [0])
while(queue):
x1,y1,x2,y2,depth = queue.popleft()
if depth >= 11:
return -1
for dx,dy in move:
nx1 = x1 + dx
ny1 = y1 + dy
nx2 = x2 + dx
ny2 = y2 + dy
if (0 <= nx1 < n and 0 <= ny1 < m) and (0 <= nx2 < n and 0 <= ny2 < m):
if board[nx1][ny1] == '#':
nx1, ny1 = x1, y1
if board[nx2][ny2] == '#':
nx2, ny2 = x2, y2
queue.append((nx1,ny1,nx2,ny2,depth+1))
elif (0 <= nx1 < n and 0 <= ny1 < m) or (0 <= nx2 < n and 0 <= ny2 < m):
return depth+1
else:
continue
return -1
n,m = map(int,sys.stdin.readline().rstrip().split())
board = []
coin = []
move = [(-1,0),(1,0),(0,-1),(0,1)]
for _ in range(n):
board.append(list(sys.stdin.readline().rstrip()))
for i in range(n):
for j in range(m):
if board[i][j] == 'o':
coin.extend([i,j])
print(bfs())
3. Learned Reference
この問題について(BAEKJOON : 14225, 16197), 我々は、より多くの情報をここで見つけました https://velog.io/@codren/BAEKJOON-14225テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol