Skip to content

Commit 7432761

Browse files
committed
[level 2] Title: 완전범죄, Time: 2.77 ms, Memory: 82.3 MB -BaekjoonHub
1 parent 21dee1a commit 7432761

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

프로그래머스/2/389480. 완전범죄/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 81 MB, 시간: 2.82 ms
7+
메모리: 82.3 MB, 시간: 2.77 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 04월 01일 16:07:34
19+
2026년 03월 04일 22:43:20
2020

2121
### 문제 설명
2222

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
import java.util.*;
22

33
class Solution {
4-
int n, m, size;
5-
int[][] info;
64
int[][][] dp;
7-
5+
int[][] info;
6+
int n, m, CNT;
87
public int solution(int[][] info, int n, int m) {
9-
preSetting(info, n, m);
8+
CNT = info.length;
9+
this.info = info;
10+
this.n = n;
11+
this.m = m;
12+
dp = new int[CNT][n][m];
13+
14+
for(int i = 0; i < CNT; i++){
15+
for(int j = 0; j < n; j++) {
16+
Arrays.fill(dp[i][j], -1);
17+
}
18+
}
19+
20+
1021
int answer = recur(0, 0, 0);
22+
if(answer == 1000) answer = -1;
1123

12-
if(500 <= answer) answer = -1;
1324
return answer;
1425
}
1526

16-
int recur(int cnt, int a, int b){
17-
if(n <= a || m <= b) return 500;
18-
if(cnt == size) return 0;
27+
private int recur(int cnt, int a, int b){
28+
if(cnt == CNT) return 0;
1929
if(dp[cnt][a][b] != -1) return dp[cnt][a][b];
2030

21-
dp[cnt][a][b] = recur(cnt + 1, a + info[cnt][0], b) + info[cnt][0];
22-
return dp[cnt][a][b] = Math.min(dp[cnt][a][b], recur(cnt + 1, a, b + info[cnt][1]));
23-
}
31+
dp[cnt][a][b] = 1000;
32+
if(a + info[cnt][0] < n) dp[cnt][a][b] = Math.min(dp[cnt][a][b], recur(cnt + 1, a + info[cnt][0], b) + info[cnt][0]);
33+
if(b + info[cnt][1] < m) dp[cnt][a][b] = Math.min(dp[cnt][a][b], recur(cnt + 1, a, b + info[cnt][1]));
2434

25-
void preSetting(int[][] info, int n, int m){
26-
this.info = info;
27-
this.n = n;
28-
this.m = m;
29-
this.size = info.length;
30-
dp = new int[size][n][m];
31-
32-
for(int i = 0; i < size; i++) {
33-
for(int j = 0; j < n; j++) Arrays.fill(dp[i][j], -1);
34-
}
35+
return dp[cnt][a][b];
3536
}
3637
}

0 commit comments

Comments
 (0)