일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 축사 배정
- 백준
- 이분탐색
- 최소스패닝트리
- Mysql5.7
- 동적계획법
- 이친수
- 알고스팟
- SpringBoot
- pythonanywhere
- 이분 매칭
- 이분매칭
- 네이버 지도 api
- tensorflow
- 피보나치수열
- 쉬운 계단 수
- 나무자르기
- Flpyd-Warshall
- 세그먼트 트리
- 분할정복
- 다이나믹 프로그래밍
- Floyd-Warshall
- 피노나치 수열
- Ubuntu64bit
- 연속합
- 알고리즘
- 최소신장트리
- VituralBox
- 백트래킹
- 코드그라운드
Archives
- Today
- Total
초보개발자
[1987] 알파벳 본문
- 입력: 세로 r 가로 c r*c로 된 대문자 집합
- 출력: 상하좌우로 움직이면서 방문했던 알파벳은 방문하지 않았을 때 최대의 길이
- 알고리즘: DFS, 백트래킹
- 소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <string> #include <cstdio> using namespace std; void DFS( int , int , int , int &); int r, c; vector<string> board; vector< bool > alphabet(26, false ); int main() { scanf ( "%d%d" , &r, &c); board = vector<string>(r); for ( int i = 0; i < r; i++) cin >> board[i]; int max = 0; DFS(0, 0, 1, max); printf ( "%d\n" , max); return 0; } void DFS( int x, int y, int d, int & m) { alphabet[board[x][y] - 'A' ] = true ; if (m < d) m = d; if (x + 1 < r && !alphabet[board[x + 1][y] - 'A' ]) DFS(x + 1, y, d + 1, m); if (y + 1 < c && !alphabet[board[x][y + 1] - 'A' ]) DFS(x, y + 1, d + 1, m); if (x - 1 >= 0 && !alphabet[board[x - 1][y] - 'A' ]) DFS(x - 1, y, d + 1, m); if (y - 1 >= 0 && !alphabet[board[x][y - 1] - 'A' ]) DFS(x, y - 1, d + 1, m); alphabet[board[x][y] - 'A' ] = false ; } |
'알고리즘 > 문제해결 소스코드' 카테고리의 다른 글
[2167] 2차원 배열의 합 (0) | 2017.09.16 |
---|---|
[9663] N-Queen (0) | 2017.07.27 |
[1002] 터렛 (0) | 2017.07.25 |
[9095] 1, 2, 3 더하기 (0) | 2017.07.25 |
[1697] 숨바꼭질 (0) | 2017.07.25 |
Comments