-
Notifications
You must be signed in to change notification settings - Fork 0
week6 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
itsnowkim
wants to merge
4
commits into
main
Choose a base branch
from
itsnowkim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
week6 #28
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| import sys | ||
|
|
||
| N = int(input()) | ||
| # input data | ||
| arr = list(map(int, sys.stdin.readline().split())) | ||
|
|
||
| # 증가하는 순열의 개수를 담은 리스트 | ||
| # 모든 숫자는 자기 자신이 순열이 될 수 있으므로 | ||
| # 최소는 1, 모두 1로 초기화 | ||
| ans = [1] * len(arr) | ||
|
|
||
| # 앞에서부터 dp 채우기 | ||
| for i in range(N): | ||
| # 자기보다 앞에 있는 원소에 대해서만 체크 필요 | ||
| for j in range(i): | ||
| # 나보다 작은경우만 고려 | ||
| # dp 배열에서 ans[i] == ans[j] 인 경우는 arr[i]가 arr[j]의 증가하는 순열에서 직전의 수라는 뜻이고 | ||
| # ans[i] < ans[j] 인 경우는 명백하게 순열의 일부이므로 ans[j]에 1을 더해주면 된다. | ||
| if arr[i] > arr[j] and ans[i] <= ans[j]: | ||
| ans[i] = ans[j] + 1 | ||
|
|
||
| print(max(ans)) |
This file contains hidden or 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,63 @@ | ||
| import sys | ||
|
|
||
| C, N = map(int, sys.stdin.readline().split()) | ||
| hotel = [] | ||
| for _ in range(N): | ||
| c, p = map(int, sys.stdin.readline().split()) | ||
| hotel.append([c, p]) | ||
|
|
||
| # 조건에 맞게 먼저 정렬 | ||
| hotel = sorted(hotel, key=lambda x: x[0]/x[1]) | ||
|
|
||
| # 2차원 배열 생성 : (N*비용의 최댓값) | ||
| row = hotel[-1][0] * C | ||
| # 비용을 담는 배열. 무조건 이 index 내에 정답 존재 | ||
| dp = [[0 for _ in range(row)] for _ in range(N)] | ||
| # print(hotel) | ||
|
|
||
| # 초기화 | ||
| for i in range(N): | ||
| dp[i][1] = (i // hotel[i][0]) * hotel[i][1] | ||
| for i in range(row): | ||
| dp[0][i] = (i // hotel[0][0]) * hotel[0][1] | ||
|
|
||
| # dp 테이블 채우기 | ||
| for i in range(1, N): | ||
| for j in range(1,row): | ||
| if dp[i][j-1] < dp[i-1][j]: | ||
| # print('위가 더 큼') | ||
| dp[i][j] = dp[i-1][j] | ||
| elif dp[i][j-1] > dp[i-1][j]: | ||
| # print('왼쪽이 더 큼') | ||
| k = j | ||
| while dp[i][k-1] == dp[i][j-1] and k >= 0: | ||
| k -= 1 | ||
| # 차이만큼 더해주기 | ||
| dp[i][j] = dp[i][j-1] + hotel[i][1] * ((j - k) // hotel[i][0]) | ||
| else: | ||
| # print('같음') | ||
| # 같음. 딱 맞는 곳까지(최소로 넣는 곳이 어딘지) 찾아가야됨 | ||
| # 위의 끝으로 먼저 이동 | ||
| k = i | ||
| while dp[k-1][j] == dp[i-1][j] and k >= 0: | ||
| k -= 1 | ||
| # 왼쪽 끝으로 이동 | ||
| q = j | ||
| while dp[k][q-1] == dp[k][j-1] and q >= 0: | ||
| q -= 1 | ||
|
|
||
| # dp[k][q] 얘가 최소임. | ||
| # 얘의 cost와 지금의 cost 차이만큼 더 집어넣을 수 있음. | ||
| dp[i][j] = dp[i][j-1] + hotel[i][1] * ((j - q)//hotel[i][0]) | ||
|
|
||
| # 새로운 cost 넘어가기 전 이전 cost가 만족하는지 확인하기 | ||
| # if dp[i][j] >= C: | ||
| # print(j) | ||
| # sys.exit(0) | ||
| # for i in dp: | ||
| # print(i) | ||
| for j in range(row): | ||
| for i in range(N): | ||
| if dp[i][j] >= C: | ||
| print(j) | ||
| sys.exit(0) | ||
This file contains hidden or 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,21 @@ | ||
| 11053 : 가장 긴 증가하는 부분 수열 (실버 II) | ||
| https://www.acmicpc.net/problem/11053 | ||
| 이코테에서 공부한 내용을 적용하기 쉬운 문제였던 것 같다. | ||
|
|
||
| i 번째 원소에 대해 증가하는 순열이 되는 조건은 | ||
| j < i에 대해 j가 더 작아야 한다. | ||
| 또한 가장 긴 증가하는 순열이어야 하기 때문에 최대 길이를 update 해 주어야 한다. | ||
|
|
||
| 따라서 전체 배열을 초기화해 놓고, 작은지 검사하고, 작다면 최대 길이를 update해 나가면서 최종 결과값을 구할 수 있다. | ||
|
|
||
| 1106 : 호텔 (골드 V) | ||
| https://www.acmicpc.net/problem/1106 | ||
| input 값이 사람과 그에 필요한 자원이므로 베낭 문제 knapsack problem을 떠올렸고, | ||
| 학교 알고리즘 수업에서 배운 table을 이용해서 풀려고 노력했지만, | ||
| 결과적으로 모든 test case는 돌아가는데, 실패했다. | ||
| 이 이유가 아직 뭔지 모르겠다. | ||
|
|
||
| 1513 : 경로 찾기 (골드 II) | ||
| https://www.acmicpc.net/problem/1513 | ||
| 아직 역량 밖의 문제인 것 같다. | ||
| 11053 문제 밑에 보면 비슷한 문제를 추천해주는데, 다 훑고 나서 골드로 넘어가야겠다. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N * 비용의 최댓값 형태의 2차원 행렬로 접근하신 것 같습니다. 그런데 비용의 최댓값이 hotel[-1][0] * C 인 이유는 무엇인가요?? 만약 row가 비용의 최댓값이라면 row = hotel[-1][0] * (C + 1) 형태가 되어야 할 것 같습니다.