Skip to content

Commit f1fad9e

Browse files
Merge pull request #687 from baekhangyeol/main
[백한결] 104차 라이브 코테 제출
2 parents ca574f7 + 8d61ddd commit f1fad9e

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# P(1) = 1
2+
# P(2) = 1
3+
# P(3) = 1
4+
# P(4) = 2
5+
# P(5) = 2
6+
# P(6) = 3
7+
# P(7) = 4
8+
# P(8) = 5
9+
# P(9) = 7
10+
# P(10) = 9
11+
12+
13+
def main():
14+
T = int(input())
15+
16+
for _ in range(T):
17+
N = int(input())
18+
19+
if N <= 3:
20+
print(1)
21+
continue
22+
23+
P = [0 for _ in range(max(N, 5))]
24+
25+
P[0] = 1
26+
P[1] = 1
27+
P[2] = 1
28+
P[3] = 2
29+
P[4] = 2
30+
31+
for j in range(5, N):
32+
P[j] = P[j-1] + P[j-5]
33+
34+
35+
print(P[N-1])
36+
37+
38+
if __name__ == "__main__":
39+
main()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 2-친구가 되는법
2+
# 1. A와 B가 친구
3+
# 2. A와 B는 친구가 아니지만 공통친구 C가 존재
4+
5+
def main():
6+
N = int(input())
7+
A = [input().strip() for _ in range(N)]
8+
9+
friendsList = set()
10+
numFriend = []
11+
12+
for i in range(N):
13+
for j in range(N):
14+
for k in range(N):
15+
if i == j:
16+
continue
17+
if A[i][j] == 'Y':
18+
friendsList.add(j)
19+
else:
20+
if A[k][i] == 'Y' and A[k][j] == 'Y':
21+
friendsList.add(j)
22+
numFriend.append(len(friendsList))
23+
friendsList.clear()
24+
25+
print(max(numFriend))
26+
27+
if __name__ == "__main__":
28+
main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from collections import deque
2+
3+
def isAdjacent(word1, word2):
4+
diff_count = 0
5+
for a, b in zip(word1, word2):
6+
if a != b:
7+
diff_count += 1
8+
if diff_count > 1:
9+
return False
10+
return diff_count == 1
11+
12+
13+
def solution(begin, target, words):
14+
if target not in words:
15+
return 0
16+
17+
visited = set()
18+
queue = deque()
19+
queue.append((begin, 0)) # 현재 단어, count 수
20+
21+
while queue:
22+
current, depth = queue.popleft()
23+
if current == target:
24+
return depth
25+
26+
for word in words:
27+
if word not in visited and isAdjacent(current, word):
28+
visited.add(word)
29+
queue.append((word, depth + 1))
30+
31+
return 0

0 commit comments

Comments
 (0)