import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Villain_Hosuk {
static int[][] light = {{1, 1, 1, 0, 1, 1, 1}, //0
{0, 0, 1, 0, 0, 0, 1}, //1
{0, 1, 1, 1, 1, 1, 0}, //2
{0, 1, 1, 1, 0, 1, 1}, //3
{1, 0, 1, 1, 0, 0, 1}, //4
{1, 1, 0, 1, 0, 1, 1}, //5
{1, 1, 0, 1, 1, 1, 1}, //6
{0, 1, 1, 0, 0, 0, 1}, //7
{1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 1, 0, 1, 1}}; //9
static int count = 0;
static int N,K,P,X;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
P = Integer.parseInt(st.nextToken());
X = Integer.parseInt(st.nextToken());
int[] num = new int[K+1];
int x = X;
for (int i = K; i >= 1; i--) {
num[i] = x%10;
x = x/10;
}
check(num);
System.out.println(count);
}
public static void check( int[] num){
for (int i = 1; i <= N; i++) { //변경할 숫자를 정한다.현재랑 똑같은건 생각 x
if(i==X)
continue;
if(change(i,num))//바꿔지면 경우의수 +1
count++;
}
}
public static boolean change(int target, int[] num){
int[] targets = new int[K+1];
for (int i = K; i >= 1; i--) {
targets[i] = target%10;
target = target/10;
}
int diff = 0;
for (int i = 1; i <= K; i++) {//숫자를 세그먼트로 변경
for (int j = 0; j <= 6 ; j++) {// 세그먼트 탐색
if(Math.abs(light[targets[i]][j]-light[num[i]][j])==1){//타겟과의 세그먼트비교하여 몇개 차이나는지 확인
diff++;
}
if(diff>P)
return false;
}
}
return true;
}
}
📢크게 보면 1부터 N까지의 수 중 변경할 숫자를 하나 정하고, 변경할 수 있는 갯수 P 안에 변경할 수 있다면, count를 증가시킨다.
막상 풀이를 쓰고보니까 간단한 풀이인것 같은데 못 풀었던 문제이다.
1부터 N까지의 수를 기준으로 탐색을 했는데
난 초기에 세그먼트에 집중해서 세그먼트를 하나 반전시키고, 같은숫자가 있나 확인하고, 이런식으로 구현하려고 해서 못풀었다.(아마 이것도 잘하는 분은 dfs같은걸로 풀지 않았을까 싶다)
언제쯤 코테가 늘까,, 이정도는 풀었으면 좋겠는데 아쉬운 문제이다. 다음에 다시 풀어보자