-
백준 2210번 : 숫자판 점프 (C 언어)c c++ 언어 공부 2023. 6. 5. 17:00
https://www.acmicpc.net/problem/2210
2210번: 숫자판 점프
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 이 가능한 경우들이다.
www.acmicpc.net
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include <stdio.h>int dy[] = { 0,0,-1,1 };int dx[] = { -1,1,0,0 };int arr[10][10] = { 0, };int count = 0;;int check[1000000];void dfs(int x, int y, int num, int cnt){if (cnt == 5){if (check[num] == 0){check[num] = 1;count++;}return;}for (int i = 0; i < 4; i++) {int ny = y + dy[i];int nx = x + dx[i];if (ny < 0 || nx < 0 || ny >= 5 || nx >= 5)continue;else{dfs(nx, ny, num * 10 + arr[nx][ny], cnt + 1);}}return;}int main(){for (int i = 0; i < 5; i++){for (int j = 0; j < 5; j++){scanf("%d", &arr[i][j]);}}for (int i = 0; i < 5; i++){for (int j = 0; j < 5; j++){dfs(i, j, arr[i][j], 0);}}printf("%d\n", count);return 0;}cs 문제풀이:
dfs를 이용해서 간단하게 해결해 주었다. 모든 위치에서 값을 처리한 후 6개를 만들어서 그 숫자가 있었는지 없었는지 체크하여 개수 증가하는 방식으로 count하였다.
'c c++ 언어 공부' 카테고리의 다른 글
백준 10825번 : 국영수 (C 언어) (0) 2023.06.07 백준 11004번 : k번째 수 (C 언어) (0) 2023.06.06 백준 10448번 : 유레카 이론(C 언어) (0) 2023.06.05 백준 1834번 : 나머지와 몫이 같은 수 (C 언어) (0) 2023.06.05 백준 2512번 : 예산 (C 언어) (0) 2023.06.04