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

Commit 286f6bf

Browse files
issue sowon-dev#42 9184
1 parent 398e922 commit 286f6bf

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

โ€Žsrc/backjoon/_9184.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/9184
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class _9184 {
9+
// ํ•จ์ˆ˜ w๋Š” 0์ดํ•˜๋Š” 1์„ ํ˜ธ์ถœํ•˜๊ณ  20์ด์ƒ์€ 20์„ ํ˜ธ์ถœํ•˜๊ธฐ๋•Œ๋ฌธ์— ๊ธธ์ด๋Š” 21๋กœ ์„ค์ •
10+
static int[][][] dp = new int[21][21][21];
11+
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringBuilder sb = new StringBuilder();
15+
// memory 24808 runtime 228
16+
while(true) {
17+
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
18+
19+
int a = Integer.parseInt(st.nextToken());
20+
int b = Integer.parseInt(st.nextToken());
21+
int c = Integer.parseInt(st.nextToken());
22+
23+
// -1 -1 -1 ์ด ๋‚˜์˜ค๋ฉด ์ข…๋ฃŒ
24+
if (a == -1 && b == -1 && c == -1) {
25+
break;
26+
}
27+
sb.append("w(" + a + ", " + b + ", " + c + ") = ").append(w(a ,b ,c)).append('\n');
28+
}
29+
System.out.println(sb);
30+
}
31+
32+
static int w(int a, int b, int c) {
33+
34+
// ์ด๋ฏธ ์ €์žฅ๋˜์–ด์žˆ๋Š” ๊ฐ’์€ ๊ทธ๋Œ€๋กœ ํ˜ธ์ถœ
35+
if(inRange(a, b, c) && dp[a][b][c] != 0) {
36+
return dp[a][b][c];
37+
}
38+
39+
if(a <= 0 || b <= 0 || c <= 0) {
40+
return 1;
41+
}
42+
43+
if(a > 20 || b > 20 || c > 20) {
44+
return dp[20][20][20] = w(20, 20, 20);
45+
}
46+
47+
if(a < b && b < c) {
48+
return dp[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
49+
}
50+
51+
return dp[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1);
52+
}
53+
54+
// a,b,c์˜ ๋ฒ”์œ„๊ฐ€ 0 ~ 20 ์‚ฌ์ด์ธ์ง€ ์ฒดํฌ
55+
static boolean inRange(int a, int b, int c) {
56+
return 0 <= a && a <= 20 && 0 <= b && b <= 20 && 0 <= c && c <= 20;
57+
}
58+
}
59+
/*
60+
input
61+
1 1 1
62+
2 2 2
63+
10 4 6
64+
50 50 50
65+
-1 7 18
66+
-1 -1 -1
67+
68+
output
69+
w(1, 1, 1) = 2
70+
w(2, 2, 2) = 4
71+
w(10, 4, 6) = 523
72+
w(50, 50, 50) = 1048576
73+
w(-1, 7, 18) = 1
74+
*/

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /