본문 바로가기

반응형

Algorithm_BOJ(백준)/완전탐색(Brute Force)

(70)
[백준 11170 c++ O] 0의 개수 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 #include using namespace std; // [백준 11170 c++ O] 0의 개수 // 문제: // 접근: 숫자에서 0 갯수 구하기 -> 완탐 -> 문자열로 변환 후 탐색 // 시간복잡도: 최대 O(20*1000000*7) = 1억4천 // 풀이: // n~m 까지 반복 // 문자열로 변환-> 문자열에서 0 탐색 // 0 갯수 출력 int t,n,m; int main()..
[백준 2304 c++ V] 창고 다각형 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 46 47 48 49 50 51 52 53 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 #include using namespace std; // [백준 2304 c++ V] 창고 다각형 // 문제: // 접근: 최소넓이 -> 스택문제인데 스택으로 안떠오름 // 접근2: 완탐 // 시간복잡도: // 풀이: // 좌표의 기둥 높이 입력 // a[i][0] = i 좌표의 높이 저장 , a..
[백준 15655 c++ OO] N과 M (6) 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 46 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15655 c++ OO] N과 M (6) // 문제: n개의 자연수증 m개의 숫자를 이용해 수열을 구현해서 출력,오름차순=입력배열 정렬하고 탐색 // 접근: 완전탐색 -> 재귀 -> 전역배열로 인덱스 인자를 넘겨줌 -> 중복방지는 오름차순에서 자동으로 해결, 오름차순=start인덱스로 ..
[백준 15654 c++ OO] N과 M (5) 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 46 47 48 49 50 51 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15654 c++ OO] N과 M (5) // 문제: n개의 자연수증 m개의 숫자를 이용해 수열을 구현해서 출력,중복방지,오름차순 // 접근: 완전탐색 -> 재귀 -> 전역배열로 인덱스 인자를 넘겨줌 -> 중복방지=방문배열, 오름차순=정렬 시키고 탐색 // 시..
[백준 15652 c++ OO] N과 M (4) 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15652 c++ OO] N과 M (4) // 접근: 완전탐색 -> 재귀 -> 전역배열로 인덱스 인자를 넘겨줌 -> 중복허용이라 방문배열 필요없음 // 시간복잡도: O(n^n 보다 작다) // 풀이1: // 수 입력 // 재귀로 전역배열로 수열 저장하고 수열의 인덱스 를 넘겨주며 저장 모든 수열 탐색 #defin..
[백준 15651 c++ OO] N과 M (3) 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15651 c++ OO] N과 M (3) // 접근: 완전탐색 -> 재귀 -> 전역배열로 인덱스 인자를 넘겨줌 -> 중복허용이라 방문배열 필요없음 // 시간복잡도: O(n^m) = 8^8 // 풀이1: // 수 입력 // 재귀로 전역배열로 수열 저장하고 수열의 인덱스 를 넘겨주며 저장 모든 수열 탐색 #defin..
[백준 15650 c++ OO] N과 M (2) 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15650 c++ OO] N과 M (2) // 접근: 오름차순 중복없는 순열 탐색 -> 완탐재귀 // 시간복잡도: O(n^m) = 8^8 = 1600만 // 풀이1: #define MAX 10 int n, m; int a[MAX]; void re(int idx, int start) { // 종료조건, 가능한 경우 if (i..
[백준 15649 c++ OO] N과 M (1) 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 46 47 48 49 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include // memset 헤더 using namespace std; // [백준 15649 c++ OO] N과 M (1) // 접근1: dp[n] = dp[n-1]+dp[n-2]+dp[n-3] -> 이번엔 완전탐색으로 구현 // 접근2: 완전탐색 -> 재귀dfs -> 재귀중간 순열 체크하면 방문한것 초기화 해야함 // 시간복잡도: n*(n-1)*....

반응형