알고리즘

백준 14501 : 퇴사

Aye Bye Eye 2020. 6. 18. 12:29

https://www.acmicpc.net/problem/14501

 

14501번: 퇴사

첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다.

www.acmicpc.net

 

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
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
 
int n;
std::pair<intint> schedule[20];
int ans;
 
void input()
{
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> schedule[i].first >> schedule[i].second;
    }
}
 
void solve(int date, int profit)
{
    if (n < date)
    {
        return;
    }
    if (n == date)
    {
        ans = ans < profit ? profit : ans;
        return;
    }
 
    solve(date + schedule[date].first, profit + schedule[date].second);
    solve(date + 1, profit);
}
 
void output()
{
    std::cout << ans;
}
 
int main()
{
    input();
    solve(00);
    output();
    return 0;
}
cs

 

나도 퇴사시켜줘

 

입사도 못해봤지만