Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 다익스트라
- 누적 합
- 구현
- DFS
- 투 포인터
- 백준
- XR Interaction Toolkit
- 스택
- 문자열
- 정렬
- 우선순위 큐
- 그리디 알고리즘
- 유니온 파인드
- 시뮬레이션
- 트리
- 알고리즘
- Team Fortress 2
- c++
- 백트래킹
- 유니티
- 브루트포스
- 수학
- 그래프
- 다이나믹 프로그래밍
- ue5
- Unreal Engine 5
- VR
- 자료구조
- BFS
- 재귀
Archives
- Today
- Total
1일1알
백준 15486 퇴사 2 C++ 본문
다이나믹 프로그래밍으로 해결할 수 있는 문제이다.
상담을 하는데 걸리는 시간이 있기 때문에 상담을 시작한 시간이 아닌, 상담이 끝난 시간을 기준으로 점화식을 세워야 한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> v(n + 1, { 0,0 });
vector<int> dp(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> v[i].first >> v[i].second;
}
for (int i = 1; i <= n; i++) {
int finish = i + v[i].first - 1;
dp[i] = max(dp[i - 1], dp[i]);
if (finish > n) continue;
dp[finish] = max(dp[finish], dp[i - 1] + v[i].second);
}
cout << dp[n];
};
'알고리즘' 카테고리의 다른 글
백준 15661번 링크와 스타트 C++ (0) | 2021.12.20 |
---|---|
백준 3079번 입국심사 C++ (0) | 2021.12.19 |
백준 16194번 카드 구매하기 2 C++ (0) | 2021.12.17 |
백준 1495번 기타리스트 C++ (0) | 2021.12.16 |
백준 2011번 암호코드 C++ (0) | 2021.12.15 |