File tree Expand file tree Collapse file tree 3 files changed +98
-0
lines changed
Expand file tree Collapse file tree 3 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments