Skip to content
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

14501: 퇴사 #12

Open
minsoo0715 opened this issue Sep 3, 2023 · 0 comments
Open

14501: 퇴사 #12

minsoo0715 opened this issue Sep 3, 2023 · 0 comments
Assignees
Labels
#다이나믹 프로그래밍 동적계획법 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들

Comments

@minsoo0715
Copy link
Owner

minsoo0715 commented Sep 3, 2023

14501: 퇴사

소스 코드

아이디어

$A_n$을 n일에 상담을 진행했을 때의 최댓값으로 정의했다.
따라서 $A_i$$i + P_i\leq k \leq N$에서 최대값을 갖는 값을 $A_k$라고 할 때 이에 $P_K$를 더한 것과 같다.

$$A_i = A_k + P_k \; (A_k는 \;\; i + P_i\leq k \leq N 에서의\;최댓값)$$
또한 $i + T_i > N$ 일 때 $A_i = P_k$ 이다.

$$A_i = P_i \; (i + T_i > N)$$

구현

재귀를 이용해 top-down 방식으로 구현, 편의를 위해서 $A_0$에 최대값 저장. 0일차($T_0 = 0$)는 무조건 포함시킨다고 생각하면 될 듯

int solve(int k = 0) {
    if(k + t[k] > n+1) { // 범위를 넘어가면 0
        return 0;
    }
    if(dp[k] != -1) {
        return dp[k];
    }

    int &ref = dp[k] = 0;

    for(int i = k + t[k]; i<=n; ++i) {  // k + t[k] <=  i <= n 내에서의 최대값
        ref = std::max(solve(i), ref);
    }

    return ref += p[k];
}

std::cout << solve(0);
@minsoo0715 minsoo0715 changed the title test . Sep 3, 2023
@minsoo0715 minsoo0715 changed the title . 14501: 퇴사 Sep 4, 2023
@minsoo0715 minsoo0715 added @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들 #다이나믹 프로그래밍 동적계획법 문제 labels Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#다이나믹 프로그래밍 동적계획법 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들
Projects
None yet
Development

No branches or pull requests

1 participant