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 | 29 | 30 |
Tags
- 티스토리챌린지
- C++
- baekjoon
- 줄 세우기
- RVO
- NRVO
- softeer
- Programmers
- UE5
- winapi
- Frustum
- const
- IFileDialog
- 백준
- C
- 오블완
- DirectX11
- 팰린드롬 만들기
- GeeksForGeeks
- Unreal Engine5
- 언리얼엔진5
- 1563
- UnrealEngine4
- 2294
- 프로그래머스
- UnrealEngine5
- directx
- RootMotion
- TObjectPtr
- algorithm
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 29756번 :: DDR 체력 관리 본문
https://www.acmicpc.net/problem/29756
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
#include <climits>
#include <bitset>
#include <cmath>
using namespace std;
int n, k;
int scores[1003] = { 0 };
int damages[1003] = { 0 };
int dp[1003][103] = { 0 };
int DFS(int index, int curHP)
{
if (index == n + 1) return 0;
int& result = dp[index][curHP];
if (result != -1) return result;
result = 0;
int newHP = min(100, curHP + k);
// 포기
result = DFS(index + 1, newHP);
// 플레이
if (newHP - damages[index + 1] >= 0)
{
result = max(result, DFS(index + 1, newHP - damages[index + 1]) + scores[index + 1]);
}
return result;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
cin >> scores[i];
}
for (int i = 1; i <= n; ++i)
{
cin >> damages[i];
}
memset(dp, -1, sizeof(dp));
cout << DFS(0, 100);
}
|
cs |
나는 그냥 문제 그대로 Top-Down으로 풀었는데, 배낭문제에서 약간 변형됐다고 봐도 된다.
체력이 회복된다는 점 말고는, 조건에 따라 특정 노드를 집거나, 안집거나 하는 과정을 거쳐 최대값을 구하는거라서 배낭문제랑 비슷하다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 17609번 :: 회문 (0) | 2025.03.18 |
---|---|
[Algorithm]Baekjoon 2461번 :: 대표 선수 (0) | 2025.03.17 |
[Algorithm]Baekjoon 3649번 :: 로봇 프로젝트 (0) | 2025.03.17 |
[Algorithm]Baekjoon 15661번 :: 링크와 스타트 (0) | 2025.03.17 |
[Algorithm]Baekjoon 2617번 :: 구슬 찾기 (0) | 2025.03.17 |