-
Notifications
You must be signed in to change notification settings - Fork 5
week19 - 끝났냐? #99
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
realain
wants to merge
1
commit into
Study-Till-Death:realain
Choose a base branch
from
realain:week19
base: realain
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
week19 - 끝났냐? #99
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/algorithmstudy/week19/MyAnswer055.java
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,32 @@ | ||
| package com.example.algorithmstudy.week19; | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.*; | ||
|
|
||
| //백준 2579번 계단 오르기 | ||
| public class MyAnswer055 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int stairCount = Integer.parseInt(br.readLine()); | ||
| int[] stairScore = new int[stairCount + 1]; | ||
| int[] dp = new int[stairCount + 1]; | ||
|
|
||
| for (int i = 1; i <= stairCount; i++) { | ||
| stairScore[i] = Integer.parseInt(br.readLine()); | ||
| } | ||
|
|
||
| dp[0] = 0; | ||
| dp[1] = stairScore[1]; | ||
|
|
||
| if(stairCount >= 2){ | ||
| dp[2] = stairScore[1] + stairScore[2]; | ||
| } | ||
|
|
||
| for (int i = 3; i <= stairCount; i++) { | ||
| dp[i] = Math.max(dp[i - 2], dp[i - 3] + stairScore[i - 1]) + stairScore[i]; | ||
| } | ||
|
|
||
| System.out.println(dp[stairCount]); | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
src/main/java/com/example/algorithmstudy/week19/MyAnswer056.java
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비슷한 풀이라 잘보감치고 도망칠게요 |
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,36 @@ | ||
| package com.example.algorithmstudy.week19; | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.*; | ||
|
|
||
| //백준 1994번 등차수열 | ||
| public class MyAnswer056 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int numCount = Integer.parseInt(br.readLine()); | ||
| int[] numArr = new int[numCount]; | ||
|
|
||
| for (int i = 0; i < numCount; i++) { | ||
| numArr[i] = Integer.parseInt(br.readLine()); | ||
| } | ||
|
|
||
| Arrays.sort(numArr); | ||
|
|
||
| int maxCount = 1; | ||
|
|
||
| Map<Integer, Map<Integer, Integer>> dp = new HashMap<>(); | ||
|
|
||
| for (int i = 0; i < numCount; i++) { | ||
| dp.put(i, new HashMap<>()); | ||
| for (int j = 0; j < i; j++) { | ||
| int diff = numArr[i] - numArr[j]; | ||
| int len = dp.get(j).getOrDefault(diff, 1) + 1; | ||
| dp.get(i).put(diff, len); | ||
| maxCount = Math.max(maxCount, len); | ||
| } | ||
| } | ||
|
|
||
| System.out.println(maxCount); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/algorithmstudy/week19/MyAnswer057.java
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,43 @@ | ||
| package com.example.algorithmstudy.week19; | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.*; | ||
|
|
||
| //백준 1695번 팰린드롬 만들기 | ||
| public class MyAnswer057 { | ||
| static int numCount; | ||
| static int[] numArr; | ||
| static int[][] dp; | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| numCount = Integer.parseInt(br.readLine()); | ||
| numArr = new int[numCount]; | ||
| dp = new int[numCount][numCount]; | ||
| for (int[] nums : dp) { | ||
| Arrays.fill(nums, -1); | ||
| } | ||
|
|
||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| for (int i = 0; i < numCount; i++) { | ||
| numArr[i] = Integer.parseInt(st.nextToken()); | ||
| } | ||
|
|
||
| int left = 0; | ||
| int right = numCount - 1; | ||
| System.out.println(checkPalindrome(left, right)); | ||
| } | ||
| static int checkPalindrome (int left, int right) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 첨에 양끝 잡고 |
||
| if(left > right) return 0; | ||
|
|
||
| if(dp[left][right] != -1) return dp[left][right]; | ||
|
|
||
| if(numArr[left] == numArr[right]) { | ||
| dp[left][right] = checkPalindrome(left + 1, right-1); | ||
| }else{ | ||
| dp[left][right] = Math.min(checkPalindrome(left + 1, right) + 1, checkPalindrome(left, right-1) + 1); | ||
| } | ||
|
|
||
| return dp[left][right]; | ||
| } | ||
| } | ||
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.
다풀고나서 이거 보니까 하 이사람 깔끔하게 한줄컷했네 생각들었음 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ