퇴사

[백준] 14501번 - 퇴사


문제 링크

주어진 상담 스케줄 내에서 가장 많이 벌 수 있는 상담료가 얼마인지를 구하는 문제이다.
n이 크지 않으므로 브루트포스로 풀이가 가능하다. 첫째날부터 순차적으로 해당 날의 상담을 수행하는 경우와, 그렇지 않는 경우 모두 탐색해보면 된다.

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
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> schedules;
int n, ans;

void consult(int day, int cost) {
    if(day == n) {
        ans = ans < cost ? cost : ans;
        return;
    } else if(day > n)
        return;

    consult(day + schedules[day].first, cost + schedules[day].second);
    consult(day + 1, cost);
}

int main(void) {
    scanf("%d", &n);

    schedules.resize(n);
    for(int i=0; i<n; ++i) {
        int day, cost;
        scanf("%d %d", &day, &cost);
        schedules[i] = {day,cost};
    }

    consult(0, 0);

    printf("%d", ans);
}

0%