-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b71696f
commit a8cd1c1
Showing
5 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
T = int(input()) | ||
|
||
|
||
def dfs(n, number): | ||
global cnt | ||
if number == n: | ||
cnt += 1 | ||
return 0 | ||
elif number > n: | ||
return 0 | ||
dfs(n, number+1) | ||
dfs(n, number+2) | ||
dfs(n, number+3) | ||
|
||
|
||
for _ in range(T): | ||
cnt = 0 | ||
n = int(input()) | ||
dfs(n, 0) | ||
print(cnt) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sys | ||
|
||
T = int(sys.stdin.readline()) | ||
|
||
dp = [0, 1, 2, 4] | ||
|
||
for _ in range(T): | ||
N = int(sys.stdin.readline()) | ||
for i in range(len(dp), N+1): | ||
print(i) | ||
dp.append(dp[i-1] + dp[i-2] + dp[i-3]) | ||
print(dp) | ||
sys.stdout.write(str(dp[N]) + "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def solution(genres, plays): | ||
answer = [] | ||
d = {e: [] for e in set(genres)} | ||
print(d) | ||
for e in zip(genres, plays, range(len(plays))): | ||
d[e[0]].append([e[1], e[2]]) | ||
genreSort =sorted(list(d.keys()), key=lambda x: sum( map(lambda y: y[0], d[x])), reverse=True) | ||
for g in genreSort: | ||
temp = [e[1] for e in sorted(d[g], key=lambda x: (x[0], -x[1]), reverse=True)] | ||
answer += temp[:min(len(temp), 2)] | ||
return answer | ||
|
||
|
||
if __name__ == '__main__': | ||
real_answer = solution(['classic', 'pop', 'classic', 'classic', 'pop'], [500, 600, 150, 800, 2500]) | ||
print(real_answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from collections import defaultdict | ||
from operator import itemgetter | ||
|
||
|
||
def solution(genres, plays): | ||
genre_play_dict = defaultdict(lambda: 0) | ||
for genre, play in zip(genres, plays): | ||
genre_play_dict[genre] += play | ||
|
||
genre_rank = [genre for genre, play in sorted(genre_play_dict.items(), key=itemgetter(1), reverse=True)] | ||
print(genre_rank) | ||
|
||
final_dict = defaultdict(lambda: []) | ||
print(final_dict) | ||
for i, genre_play_tuple in enumerate(zip(genres, plays)): | ||
print(genre_play_tuple) | ||
final_dict[genre_play_tuple[0]].append((genre_play_tuple[1], i)) | ||
print(final_dict) | ||
|
||
answer = [] | ||
for genre in genre_rank: | ||
one_genre_list = sorted(final_dict[genre], key=itemgetter(0), reverse=True) | ||
print(one_genre_list) | ||
if len(one_genre_list) > 1: | ||
answer.append(one_genre_list[0][1]) | ||
answer.append(one_genre_list[1][1]) | ||
else: | ||
answer.append(one_genre_list[0][1]) | ||
|
||
return answer | ||
|
||
|
||
if __name__ == '__main__': | ||
real_answer = solution(['classic', 'pop', 'classic', 'classic', 'pop'], [500, 600, 150, 800, 2500]) | ||
print(real_answer) |