본문 바로가기

분류 전체보기76

[2096] 내려가기 // 2096 내려가기 - 못 ㅜ품 // DP, 메모리 최적화 #include using namespace std; int n; int DMIN[2][3] = {0, }; // int DMAX[2][3] = {0, }; // int A[3]; // int a, b, c; int minn, maxx; // n은 90미만 정수 int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; // 100,000 -> 입력이 큰데 비해 메모리는 4MB // 초기화 for(int i=0; i> b >> c; A[0] = a; A[1] = b; A[2] = c; DMIN[i%2][0] = min(DMIN[(i+1)%2][0], DMIN[(i+1)%2][1]) + A[0];.. 2024. 2. 14.
2504 괄호의 값 // 2504 괄호의 값 -못품 ㅠ // stack s; // 괄호는 안쓰는 값으로 -> -1 #include using namespace std; string str; int res; stack st; void check(void){ for(int i=1; i str; //str.replace(str.begin(), str.end(), "()", "2"); //str.replace(str.begin(), str.end(), "[]", "3"); for(int i=0; i 맞으면 2 // [ 들어오면 ] 닫혔는지 확인 -> 맞으면 3 } //cout 2024. 2. 14.
[1927] 최소힙 // 1927 최소힙 #include using namespace std; int x; int n; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; // 100,000까지 // x는 0~2^31 // x가 자연수 -> 배열에 x를 추가 // x가 0 -> 가장 작은 값을 출력하고, 그 값을 배열에서 제거 priority_queue heap; // 올림차순 - 최소힙 for(int i=0; i> x; if(x > 0){ // 배열에 x를 추가 heap.push(x); }else{ // 가장 작은 값 출력, 그 값을 배열에서 제거 if (heap.empty()) { cout 2024. 2. 14.
[2748] 피보나치수2 // 2748 피보나치수2 // 자료형에 주의 -> 오버플로우 #include using namespace std; int n; long long arr[91] = {0, }; long long ans; long long fib(int n){ if(n 0){ // 답이 존재하면 return arr[n]; } arr[n] = fib(n-1) + fib(n-2); return arr[n]; } } // n은 90미만 정수 int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; fib(n); ans = arr[n]; cout 2024. 2. 14.