diff --git "a/miniron-v/DP/1793-\355\203\200\354\235\274\353\247\201.cpp" "b/miniron-v/DP/1793-\355\203\200\354\235\274\353\247\201.cpp" new file mode 100644 index 0000000..986bd48 --- /dev/null +++ "b/miniron-v/DP/1793-\355\203\200\354\235\274\353\247\201.cpp" @@ -0,0 +1,55 @@ +#include +#include +#include + +// 문자열 덧셈 +std::string string_add(std::string a, std::string b) { + std::reverse(a.begin(), a.end()); + std::reverse(b.begin(), b.end()); + + // a > b, always. + if (a.size() < b.size()) { + std::swap(a, b); + } + + else if (a.size() == b.size()) { + a += '0'; + } + + int i = 0, carry = 0; + std::string sum = ""; + for (; i < b.size(); ++i) { + int num = (a[i] - '0') + (b[i] - '0') + carry; + sum.push_back(num % 10 + '0'); + carry = num / 10; + } + + a[i] += carry; + + // a가 남은 경우 + while (i < a.size()) { + sum += a[i++]; + } + + if (sum[--i] == '0') { + sum.pop_back(); + } + + std::reverse(sum.begin(), sum.end()); + + return sum; +} + +int main() { + int n; + while (std::cin >> n) { + std::vector dp(n + 1, "1"); + + for (int i = 2; i <= n; ++i) { + dp[i] = string_add(dp[i - 1], dp[i - 2]); + dp[i] = string_add(dp[i], dp[i - 2]); + } + + std::cout << dp[n] << " "; + } +} \ No newline at end of file diff --git a/miniron-v/README.md b/miniron-v/README.md index eac5d20..e1e10c4 100644 --- a/miniron-v/README.md +++ b/miniron-v/README.md @@ -14,6 +14,8 @@ | 10차시 | 2024.01.28 | 그래프 | [토마토](https://www.acmicpc.net/problem/7569) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/38) | | 번외 - 10 | 2024.01.30 | 그래프 | [하이퍼 토마토](https://www.acmicpc.net/problem/17114) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/42) | | 11차시 | 2024.01.31 | 브루트포스 | [감소하는 수](https://www.acmicpc.net/problem/1038) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/43) | -| 12차시 | 2024.01.31 | DP | [점프 점프](https://www.acmicpc.net/problem/11060) | [#48](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/48) | -| 13차시 | 2024.01.31 | DP | [퇴사 2](https://www.acmicpc.net/problem/15486) | [#50](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/50) | +| 12차시 | 2024.02.03 | DP | [점프 점프](https://www.acmicpc.net/problem/11060) | [#48](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/48) | +| 13차시 | 2024.02.06 | DP | [퇴사 2](https://www.acmicpc.net/problem/15486) | [#50](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/50) | +| 14차시 | 2024.02.11 | 그래프, DP | [ACM Craft](https://www.acmicpc.net/problem/1005) | [#53](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/53) | +| 15차시 | 2024.02.15 | DP, 큰 수 연산 | [타일링](https://www.acmicpc.net/problem/1793) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/56) | --- diff --git "a/miniron-v/\352\267\270\353\236\230\355\224\204/1005-ACM Craft.cpp" "b/miniron-v/\352\267\270\353\236\230\355\224\204/1005-ACM Craft.cpp" new file mode 100644 index 0000000..50a6140 --- /dev/null +++ "b/miniron-v/\352\267\270\353\236\230\355\224\204/1005-ACM Craft.cpp" @@ -0,0 +1,90 @@ +#include +#include +#include + +int n, k, w; + +// dp (시간 계산) +std::vector cost; +std::vector min_cost; + +// 위상정렬 (순서 지정) +std::vector> graph; +std::vector inDegree; +std::queue queue; + +std::vector sorted; + +void input() { + std::cin >> n >> k; + + cost.assign(n + 1, 0); + min_cost.assign(n + 1, 0); + + graph.assign(n + 1, std::vector(0)); + inDegree.assign(n + 1, 0); + + sorted.clear(); + + for (int i = 1; i <= n; ++i) { + std::cin >> cost[i]; + } + + int a1, a2; + while (k--) { + std::cin >> a1 >> a2; + graph[a1].push_back(a2); + ++inDegree[a2]; + } + + std::cin >> w; +} + +void topologySort() { + for (int i = 1; i < inDegree.size(); i++) { + if (inDegree[i] == 0) { + queue.push(i); + } + } + + int a; + while (queue.empty() == false) { + a = queue.front(); + queue.pop(); + + sorted.push_back(a); + + for (int i : graph[a]) { + if (--inDegree[i] == 0) { + queue.push(i); + } + } + } +} + +int minCost() { + for (int a : sorted) { + min_cost[a] += cost[a]; + + for (int i : graph[a]) { + if (min_cost[a] > min_cost[i]) { + min_cost[i] = min_cost[a]; + } + } + } + + return min_cost[w]; +} + +int main() { + int t; + std::cin >> t; + + while (t--) { + input(); + + topologySort(); + + std::cout << minCost() << "\n"; + } +} \ No newline at end of file