Skip to content

[강신지-13주차 알고리즘 스터디] #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: akstp1717/week13
Choose a base branch
from

Conversation

ksinji
Copy link
Contributor

@ksinji ksinji commented May 18, 2025

🚀 싸피 15반 알고리즘 스터디 13주차 [강신지]

📌 문제 풀이 개요

  • 이번 PR에서는 다음 6문제의 풀이를 포함합니다.
  • 각 문제에 대한 풀이 과정과 접근 방식을 설명합니다.

✅ 문제 해결 여부

  • 문제 1
  • 문제 2
  • 문제 3
  • 문제 4
  • 문제 5
  • 문제 6

💡 풀이 방법

문제 1: 스티커

문제 난이도
실버 1

문제 유형
DP

접근 방식 및 풀이
현재 위치의 스티커를 선택할 수 있는 경우의 최댓값을 DP로 계산했습니다.

			int[][] dp = new int[2][n+1];
			dp[0][1] = sticker[0][0];
			dp[1][1] = sticker[1][0];

			for (int j=2; j<n+1; j++){
				for (int i=0; i<2; i++){
					dp[i][j] = Math.max(Math.max(dp[0][j-2], dp[1][j-2])+sticker[i][j-1], dp[(i+1)%2][j-1]+sticker[i][j-1]);
				}
			}

문제 2: 곱셈

문제 난이도
실버 1

문제 유형
수학

접근 방식 및 풀이
거듭제곱을 분할 정복 방식으로 계산하며 모듈러 연산을 적용했습니다.

	// mod 연산의 성질 활용
	static long modPow(int a, int b, int m) {
	    if (b == 0) return 1;
	    long half = modPow(a, b / 2, m);
	    long result = (half * half) % m;  
	    if (b % 2 == 1) {                 
	        result = (result * a) % m;
	    }
	    return result;
	}

문제 3: 후위 표기식

문제 난이도
골드 2

문제 유형
자료구조

접근 방식 및 풀이
문자와 괄호, 그 외 기호 등 조건을 나누어 구현했습니다.

for (int i = 0; i < infix.length(); i++) {
            char c = infix.charAt(i);

            if (c >= 'A' && c <= 'Z') {
                postfix.append(c);
            } else if (c == '(') {
                oper.addLast(c);
            } else if (c == ')') {
                while (!oper.isEmpty() && oper.peekLast() != '(') {
                    postfix.append(oper.pollLast());
                }
                oper.pollLast();
            } else {
                while (!oper.isEmpty() && prec(oper.peekLast()) >= prec(c)) {
                    postfix.append(oper.pollLast());
                }
                oper.addLast(c);
            }
        }

        while (!oper.isEmpty()) {
            postfix.append(oper.pollLast());
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant