[BOJ] 14501번 : 퇴사

2024. 9. 2. 19:54Algorithm

1. problem : 

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

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;
int n;
int t[20]; 
int p[20];
int d[20];

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> t[i] >> p[i]; 

	for (int i = n; i >= 1; i--) {
		if (t[i] + i <= n + 1) {
			d[i] = max(d[i + t[i]] + p[i], d[i + 1]);
		}
		else d[i] = d[i + 1];
	}
	cout << *max_element(d, d + n + 1) << '\n';
}

source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/14501.cpp

 

basic-algo-lecture/0x10/solutions/14501.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com