Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- ๋ฐ์ดํฌ์คํธ๋ผ
- ์ต๋จ ๊ฒฝ๋ก
- ๋ฌธ์์ด
- Reversing
- dfs
- dynamic debugging
- c++
- ๋ถํ ์ ๋ณต
- OS
- thymeleaf
- ์๋ฎฌ๋ ์ด์
- ๋ฐฑํธ๋ํน
- GCP
- java
- ์ด๋ถ ํ์
- ๊ทธ๋ฆฌ๋
- ๊ตฌํ
- ๋์ ํฉ
- error
- ๋งต
- ์ฌ๊ท
- web
- ์์ ์ ๋ ฌ
- JPA
- BFS
- Spring
- CVE
- DP
- ์คํ
- ์ฐ์ ์์ ํ
Archives
- Today
- Total
hades
[Baekjoon] 1003๋ฒ: ํผ๋ณด๋์น ํฉ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/1003
๐ ์ค๊ณ
์ฌ๊ท ํจ์๋ก ์ค๊ณํ ๊ฒฝ์ฐ, ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
fibonacci(N)์ ์ถ๋ ฅํ์ ๋, 0๊ณผ 1์ ํธ์ถ ํ์๋ fibonacci(N-1)๊ณผ fibonacci(N-2)์ 0๊ณผ 1์ ํธ์ถ ํ์์ ๊ด๋ จ์ด ์์ผ๋ฏ๋ก, ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ์ด์ฉํ์ฌ ํด๊ฒฐํ ์ ์๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t, n;
vector<pair<int, int>> dp(41, {0, 0});
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> t;
dp[0].first = 1;
dp[1].second = 1;
for (int i=2; i<=40; i++){
dp[i].first = dp[i-1].first + dp[i-2].first;
dp[i].second = dp[i-1].second + dp[i-2].second;
}
for (int j=0; j<t; j++){
cin >> n;
cout << dp[n].first << " " << dp[n].second << "\n";
}
return 0;
}
๐ ๋ฉ๋ชจ
A์ ๊ฐ์ ๊ตฌํ๋๋ฐ B์ C์ ๊ฐ์ ์ด์ฉํ๋ค๋ฉด, ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ์ด์ฉํ ์ ์๋ค.
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 1074๋ฒ: Z (0) | 2024.07.02 |
---|---|
[Baekjoon] 1012๋ฒ: ์ ๊ธฐ๋ ๋ฐฐ์ถ (0) | 2024.07.02 |
[Baekjoon] 1920๋ฒ: ์ ์ฐพ๊ธฐ (0) | 2024.07.01 |
[Baekjoon] 1463๋ฒ: 1๋ก ๋ง๋ค๊ธฐ (0) | 2024.07.01 |
[Baekjoon] 1926๋ฒ: ๊ทธ๋ฆผ (0) | 2024.07.01 |