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
- ๋ฐ์ดํฌ์คํธ๋ผ
- thymeleaf
- BFS
- c++
- ๋ถํ ์ ๋ณต
- ์์ ์ ๋ ฌ
- dynamic debugging
- ๊ทธ๋ฆฌ๋
- ์ฌ๊ท
- Reversing
- GCP
- Spring
- DP
- OS
- ๋ฐฑํธ๋ํน
- web
- ๋งต
- ์ฐ์ ์์ ํ
- ๋์ ํฉ
- ์ด๋ถ ํ์
- CVE
- java
- error
- ๋ฌธ์์ด
- ๊ตฌํ
- dfs
- ์คํ
- ์๋ฎฌ๋ ์ด์
- JPA
- ์ต๋จ ๊ฒฝ๋ก
Archives
- Today
- Total
hades
[Baekjoon] 9095๋ฒ: 1, 2, 3 ๋ํ๊ธฐ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/9095
๐ ์ค๊ณ
1 = 1
2 = 1 + 1 = 2
3 = 1 + 1 + 1 = 2 + 1 = 1 + 2 = 3
4 = 1 + 1 + 1 + 1 = 2 + 1 + 1 = 1 + 2 + 1 = 3 + 1 = 1 + 1 + 2 = 2 + 2 = 1 + 3
์ผ๋ก dp[i] = dp[i-1]+dp[i-2]+dp[i-3]์ด๋ผ๋ ๊ฒ์ ์ ์ ์๋ค. dp[0]์ 0์ผ๋ก ์ด๊ธฐํํ๋ฉด, 1๋ถํฐ ๋ฐ๋ณต๋ฌธ์ ์์ํ ์ ์๋ค.
๋จ, ๋ฒ์๋ฅผ ์ฃผ์ํด์ผ ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
using namespace std;
int t, n;
vector<int> dp(11);
int main(void)
{
dp[0] = 1;
for (int i = 1; i < 11; i++) {
if (i - 1 >= 0) {
dp[i] += dp[i - 1];
}
if (i - 2 >= 0) {
dp[i] += dp[i - 2];
}
if (i - 3 >= 0) {
dp[i] += dp[i - 3];
}
}
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
cout << dp[n] << "\n";
}
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 11286๋ฒ: ์ ๋๊ฐ ํ (1) | 2024.07.23 |
---|---|
[Baekjoon] 10026๋ฒ: ์ ๋ก์์ฝ (2) | 2024.07.22 |
[Baekjoon] 7662๋ฒ: ์ด์ค ์ฐ์ ์์ ํ (0) | 2024.07.17 |
[Baekjoon] 7569๋ฒ: ํ ๋งํ (0) | 2024.07.16 |
[Baekjoon] 5525๋ฒ: IOIOI (0) | 2024.07.15 |