|
| 1 | +```java |
| 2 | +import java.io.*; |
| 3 | +import java.util.*; |
| 4 | + |
| 5 | +public class boj22251 { |
| 6 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 7 | + static StringTokenizer st; |
| 8 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 9 | + static int nextInt() {return Integer.parseInt(st.nextToken());} |
| 10 | + |
| 11 | + static int[][] digit = { |
| 12 | + {0, 4, 3, 3, 4, 3, 2, 3, 1, 2}, |
| 13 | + {4, 0, 5, 3, 2, 5, 6, 1, 5, 4}, |
| 14 | + {3, 5, 0, 2, 5, 4, 3, 4, 2, 3}, |
| 15 | + {3, 3, 2, 0, 3, 2, 3, 2, 2, 1}, |
| 16 | + {4, 2, 5, 3, 0, 3, 4, 3, 3, 2}, |
| 17 | + {3, 5, 4, 2, 3, 0, 1, 4, 2, 1}, |
| 18 | + {2, 6, 3, 3, 4, 1, 0, 5, 1, 2}, |
| 19 | + {3, 1, 4, 2, 3, 4, 5, 0, 4, 3}, |
| 20 | + {1, 5, 2, 2, 3, 2, 1, 4, 0, 1}, |
| 21 | + {2, 4, 3, 1, 2, 1, 2, 3, 1, 0} |
| 22 | + }; |
| 23 | + static int N, K, P, X, answer; |
| 24 | + public static void main(String[] args) throws Exception { |
| 25 | + nextLine(); |
| 26 | + N = nextInt(); // N층까지 이용 가능 |
| 27 | + K = nextInt(); // 숫자 길이 |
| 28 | + P = nextInt(); // 1~P개 반전 |
| 29 | + X = nextInt(); // 실제 층 |
| 30 | + |
| 31 | + solve(0, 1, 0, 0); |
| 32 | + |
| 33 | + System.out.println(answer-1); |
| 34 | + } |
| 35 | + |
| 36 | + static void solve(int idx, int ten, int now, int cnt) { |
| 37 | + if (now > N || cnt > P) return; |
| 38 | + if (idx == K) { |
| 39 | + if (now != 0) answer++; |
| 40 | + return; |
| 41 | + } |
| 42 | + for(int i = 0; i < 10; i++) { |
| 43 | + solve(idx+1, ten*10, i*ten+now, cnt+digit[X/ten%10][i]); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +``` |
0 commit comments