From 609cbbefc0bf336cb28e9b004eddc455be7ae1d0 Mon Sep 17 00:00:00 2001 From: Minsung_Kang Date: Sun, 25 Feb 2024 14:34:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?2024-02-25=20=EC=9E=85=EB=8C=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rivkms/Backtracking/31413.cpp | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rivkms/Backtracking/31413.cpp 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 From 764fb5b9c3cca3c3668f59381c2a1858ff952cbd Mon Sep 17 00:00:00 2001 From: Minsung_Kang Date: Sun, 25 Feb 2024 14:35:17 +0900 Subject: [PATCH 2/2] =?UTF-8?q?2024-02-25=20=EC=9E=85=EB=8C=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rivkms/README.md | 1 + 1 file changed, 1 insertion(+) 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) | ---