Skip to content

Commit

Permalink
2024-02-15
Browse files Browse the repository at this point in the history
  • Loading branch information
miniron-v committed Feb 14, 2024
1 parent a66e31c commit b78496c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 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] << " ";
}
}
1 change: 1 addition & 0 deletions miniron-v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
| 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) |
---

0 comments on commit b78496c

Please sign in to comment.