Skip to content

Commit

Permalink
Merge pull request #56 from AlgoLeadMe/15-miniron-v
Browse files Browse the repository at this point in the history
15-miniron-v
  • Loading branch information
miniron-v committed Feb 18, 2024
2 parents efeb6c6 + b78496c commit 4377645
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 2 deletions.
55 changes: 55 additions & 0 deletions miniron-v/DP/1793-ํƒ€์ผ๋ง.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
#include <vector>
#include <algorithm>

// ๋ฌธ์ž์—ด ๋ง์…ˆ
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<std::string> 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] << " ";
}
}
6 changes: 4 additions & 2 deletions miniron-v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
90 changes: 90 additions & 0 deletions miniron-v/๊ทธ๋ž˜ํ”„/1005-ACM Craft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <iostream>
#include <vector>
#include <queue>

int n, k, w;

// dp (์‹œ๊ฐ„ ๊ณ„์‚ฐ)
std::vector<int> cost;
std::vector<int> min_cost;

// ์œ„์ƒ์ •๋ ฌ (์ˆœ์„œ ์ง€์ •)
std::vector<std::vector<int>> graph;
std::vector<int> inDegree;
std::queue<int> queue;

std::vector<int> sorted;

void input() {
std::cin >> n >> k;

cost.assign(n + 1, 0);
min_cost.assign(n + 1, 0);

graph.assign(n + 1, std::vector<int>(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";
}
}

0 comments on commit 4377645

Please sign in to comment.