Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[6주차] 고다혜 #76

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

Merged
jewan100 merged 13 commits into GreatAlgorithm-Study:main from KodaHye:main
Oct 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
0a2333a
고다혜: [CT] 테트리스 블럭 안의 합 최대화 하기_241014
KodaHye Oct 14, 2024
e3d36e8
고다혜: [BOJ] 2110 공유기 설치_241015
KodaHye Oct 15, 2024
8817755
고다혜: [BOJ] 2805 나무 자르기_241015
KodaHye Oct 15, 2024
2206d94
고다혜: [BOJ] 7579 앱_241016
KodaHye Oct 16, 2024
830c013
고다혜: [BOJ] 9084 동전_241016
KodaHye Oct 16, 2024
7908b54
고다혜: [PG] 43238 입국심사_241017
KodaHye Oct 17, 2024
1f8497f
고다혜: [SQL] 대장균의 크기에 따라 분류하기1_241003
KodaHye Oct 17, 2024
6f29099
고다혜: [SQL] 물고기 종류 별 잡은 수 구하기_241008
KodaHye Oct 17, 2024
9746f3a
고다혜: [SQL] 월별 잡은 물고기 수 구하기_241010
KodaHye Oct 17, 2024
44b5fd5
고다혜: [SQL] 있었는데요 없었습니다_241015
KodaHye Oct 17, 2024
bd730ca
고다혜: [SQL] 오랜 기간 보호한 동물(1)_241017
KodaHye Oct 17, 2024
cafebef
고다혜: [SQL] 보호소에서 중성화한 동물_241017
KodaHye Oct 17, 2024
5a6e60c
고다혜: [PG] 42861 섬 연결하기_241018
KodaHye Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import java.io.*;
import java.util.*;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시! 이슈에 적어주신 블럭이 위치하는 모든 경우의 수가 왜 3 * 3 * 3인지 설명해주실 수 있을까요!?🥹

Copy link
Contributor Author

@KodaHye KodaHye Oct 14, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우선 맵의 크기만큼 반복문을 실행하기 때문에 N ×ばつ M을 했고,
(저는 depth를 0부터 시작했기 때문에) depth가 0 ~ 2번째까지 dfs를 반복하고, 반복을 줄이기 위해 상, 좌, 우 방향만 고려했기 때문에 한 지점에 대해 총 3 * 3 * 3가지 경우가 있다고 생각했습니다!

yeahdy reacted with thumbs up emoji
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 지점에 대해 방향을 상, 하, 좌, 우 모두 고려해도 되지만, 상, 좌, 우로도 충분히 모든 경우의 수를 나타낼 수 있습니다!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하!!!!! 그렇군요 설명 감사합니다!!👍☺️
방향도 어짜피 for문으로 내려오면서 탐색하니까 3방향만 살피면 되군요!! 근데근데! 그럼 하,좌,우 맞을까요!? 코드도 하로 쓰신거같아서요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 네! 하, 좌, 우로 했네요!! 근데 상, 좌, 우로 해도 상관 없을 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

으어 전 for문타고 내려가면서 봐서 하좌우라고 생각했는데 상일 경우도 왜 상관이 없는걸까요!?ᅲᅲᄐᄏᄏᄐᄐ큐ᅲᅲ
너무 자꾸 질문을 해가지구,,, 자세한건 리뷰때 듣도록 하겠습니다! 답변 감사합니다ᅲᅲ

Copy link
Contributor Author

@KodaHye KodaHye Oct 14, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



간단히 설명드리면 이 그림에서 (1, 1)에서 하, 하, 우로 가는 경우와 (3, 2)에서 좌, 상, 상으로 가는 경우가 동일한 블럭을 나타내는데요, L자 블럭 이외에도 ᄆ, l, ᅡ 모양 모두 상, 하 중 하나만 사용하면 출발점이 어디인지만 다를 뿐, 모든 모양을 만들 수 있다는 것을 알 수 있습니다!

(이해가 되지 않는 부분이 있다면 계속 질문 주셔도 괜찮습니다!!)

yeahdy, yeongleej, and baexxbin reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헐!!!!! 완전 친절하게 그림까지 짱입니다....💖 감사합니다!!! 아하 이제 완전 이해갔습니다! 위아래 중 한쪽만 막아줘도 되서 상관없는거였군요!!!! 최고입니다!!!!!!!👍

KodaHye reacted with heart emoji
public class DH_테트리스_블럭_안의_합_최대화_하기 {
static int N, M, result, max;
static int[][] map;
// 중복을 최대한 줄여주기 위해 상, 좌, 우 방향만 사용
static int[] dr = {0, 1, 0}, dc = {-1, 0, 1};
static boolean[][] v;

static void solution() {
// dfs 과정에서 원상복구 되기 때문에
// 새로 생성하지 않아도 됨
// dfs를 할 때마다 new boolean을 한다면 메모리 초과 발생
v = new boolean[N][M];

for(int r = 0; r < N; r++) {
for(int c = 0; c < M; c++) {
// r, c 지점에서 dfs 시작
v[r][c] = true;
dfs(r, c, map[r][c], 0);
v[r][c] = false;

}
}

System.out.println(result);
}

static void dfs(int r, int c, int sum, int depth) {
// 현재까지의 합 + (전체 - 남은 depth 값) * map에서 최대값 <= result라면
// 현재 r, c 지점에서 남은 depth값 보다 더 dfs를 하더라도 최대값이 될 수 없으므로
// return
if(sum + (3 - depth) * max <= result) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇! 저는 이렇게 조건을 추가하니까 시간이 더 걸리던데! 혹시 더 빨라지셨나요!?

Copy link
Contributor Author

@KodaHye KodaHye Oct 14, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
저는 조건 추가한게 더 짧습니다!

수빈님 코드 중 mx > mx*(4-depth)+total)mx*(4-depth)+total이 부분에서 mx가 아니라 board에서의 최대값을 곱해줘야될 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

으악 그러네요!! 보드에서 맥스값을 넣어줘야하는데 그냥 맥스값을 넣었군요 제가... 코드를 좀 더 꼼꼼하게 짜는 연습을 더해야할거같네요!ᅲᅲ 감사합니다!!!

KodaHye reacted with thumbs up emoji
// depth가 3이라면 return
if(depth == 3) {
result = Math.max(result, sum);
return;
}

for(int d = 0; d < 3; d++) {
int nr = r + dr[d];
int nc = c + dc[d];

if(!check(nr, nc) || v[nr][nc]) continue;

// T자형 블럭을 만들어주기 위한 부분
// nr, nc 지점은 갔다고 방문 체크해주고
// 다음 위치 값은 nr, nc가 아닌 r, c로 설정해주기
if(depth == 1) {
v[nr][nc] = true;
dfs(r, c, sum + map[nr][nc], depth + 1);
v[nr][nc] = false;
}

// T자 외의 부분을 만들어 주기 위한 부분
v[nr][nc] = true;
dfs(nr, nc, sum + map[nr][nc], depth + 1);
v[nr][nc] = false;
}

}

static boolean check(int r, int c) {
return r >= 0 && r < N && c >= 0 && c < M;
}
public static void main(String[] args) throws Exception {
initInput();
solution();
}

static void initInput() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

map = new int[N][M];
for(int r = 0; r < N; r++) {
st = new StringTokenizer(br.readLine());
for(int c = 0; c < M; c++) {
map[r][c] = Integer.parseInt(st.nextToken());
max = Math.max(map[r][c], max);
}
}
}
}

AltStyle によって変換されたページ (->オリジナル) /