diff --git a/rivkms/Backtracking/31413.cpp b/rivkms/Backtracking/31413.cpp new file mode 100644 index 0000000..2b6500d --- /dev/null +++ b/rivkms/Backtracking/31413.cpp @@ -0,0 +1,59 @@ +// <미완> +#include +#include +#include + +using namespace std; +int N, M, A, D; +vector vec; +pair compare(const pair& p1, const pair& p2) { + if (p1.second > p2.second) { + if (p2.first >= M) { + return p2; + } + return p1; + } + if (p1.second < p2.second) { + if (p1.first >= M) { + return p1; + } + return p2; + } + return p1.first > p2.first ? p1 : p2; +} + +pair dfs(bool blood, int point, int num, int n) { + if (n == N) { + return pair(point, num); + } + if (!blood) { + point += vec[n]; + pair p1 = dfs(false, point, num, n + 1); + pair p2 = dfs(true, point, num, n + 1); + return compare(p1, p2); + } + else { + point += A; + num += D; + return dfs(false, point, num, n + 1); + } +} + +int main() { + int tmp; + cin >> N >> M; + for (int i = 0; i < N; i++) { + cin >> tmp; + vec.push_back(tmp); + } + cin >> A >> D; + + pair p = dfs(false, 0, 0, 0); + if (p.first >= M) { + cout << -1; + } + else { + cout << p.second; + } + return 0; +} \ No newline at end of file diff --git a/rivkms/README.md b/rivkms/README.md index fdba398..98fae2c 100644 --- a/rivkms/README.md +++ b/rivkms/README.md @@ -6,4 +6,5 @@ | 2차시 | 2024.02.15 | Recursion | [하노이 탑 이동 순서](https://www.acmicpc.net/problem/11729) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/8) | | 3차시 | 2024.02.18 | DP | [하노이 탑 이동 순서](https://www.acmicpc.net/problem/10844) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/11) | | 4차시 | 2024.02.18 | Backtracking | [N-queen](https://www.acmicpc.net/problem/9663) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/13) | +| 5차시 | 2024.02.24 | Backtracking | [입대](https://www.acmicpc.net/problem/31413) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/18) | ---