분류 전체보기 287

C++ 알고리즘 - 백준 1904 01타일

https://www.acmicpc.net/problem/1904 #include #define endl "\n"using namespace std;/******** 전역변수 ********/long long fibo[1000002] = { 0, 1, 1, };/******** 함 수 ********/int main(void) { /******** C++ INIT ********/ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /******** 지역변수 ********/ int input; /******** 구 현 ********/ cin >> input; // 해당 문제는 피보나치 수열 문제이기 때문에 수열 생성 for (int i..

알고리즘 2025.01.22
C++ 알고리즘 - 백준 9184 신나는 함수 실행 (동적 계획법 / 재귀)

https://www.acmicpc.net/problem/9184 #include #define endl "\n"using namespace std;/******** 전역변수 ********/int arr[21][21][21];/******** 함 수 ********/int w(int a, int b, int c) { if (a 20 || b > 20 || c > 20) return w(20, 20, 20); // 저장된 값은 재귀 호출 및 계산하지 않고 바로 리턴 else if (arr[a][b][c] != 0) return arr[a][b][c]; // 리턴하지 않고 값 저장 else if (a > input1 >> input2 >> input3; if (input1 == -1 && inpu..

알고리즘 2025.01.22
C++ - bits/stdc++.h 헤더파일에서 unordered_map & set 등 사용하기

bits/stdc++.h 헤더파일을 추가하여 사용하여도 unordered_map, unordered_set 등을 사용할때는 직접 include를 시켜줘야 했다. 왜 그런가 싶어 헤더파일을 열어보니,#if __cplusplus >= 201103L#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif  ???__cplusplus 가 201103L 이상이어야 한다?? 그래서 해결방법을 찾았다. Visual Studio에서 프로젝트 - 프로젝트 속성구성..

C++ 2025.01.22
C++ 알고리즘 - 백준 24416 알고리즘 수업 - 피보나치 수 1

https://www.acmicpc.net/problem/24416 #include #define endl "\n"using namespace std;/******** 전역변수 ********/int fibo[50] = { 0, 1, 1, };int cnt1 = 0, cnt2 = 0;/******** 함 수 ********/int fibonacci(int n) { if (n == 1 || n == 2) { cnt1++; return 1; } else return fibonacci(n - 1) + fibonacci(n - 2);}int main(void) { /******** C++ INIT ********/ ios::sync_with_stdio(false); cin.tie(NULL); cout...

알고리즘 2025.01.21
C++ 알고리즘 - 백준 4779 칸토어 집합

#include #define endl "\n"using namespace std;/******** 전역변수 ********/vector kan(550000);/******** 함 수 ********/void kantoa(int n, int m){ // n: 문자 자를 인덱스 위치, m: 자를 개수 // 자를 개수가 없다면 리턴 if (m == 0) return; // n의 위치부터 m까지 공백 처리 for(int i = n; i 3, 3 => 1, 1 kantoa(n - (m / 3) - (m / 3), m / 3); //재귀함수 호출 (뒤로 탐색) //ex: 9, 9 => 21, 3 => 25, 1 kantoa(n + m + (m / 3), m / ..

알고리즘 2025.01.21
C++ 알고리즘 - 백준 15650 N과 M (2) (백트래킹)

https://www.acmicpc.net/problem/15650 #include #define endl "\n"using namespace std;/******** 전역변수 ********/int n, m;int arr[9] = { 0 };bool visited[9] = { false };/******** 함 수 ********/void dfs(int idx, int num) { // DFS : 깊이 우선 탐색 if (num == m) { // 출력해야 할 만큼의 수(m) 가 되었을 때 출력 for (int i = 0; i idx 매개변수 dfs(i, num + 1); // 끝(m) 까지 방문 후 출력, 이후 방문하지 않은 상태로 변경 visited[i] = false; } ..

알고리즘 2025.01.20