반응형
- 문제
- 작성 코드
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int t, max =0;
cin >> t;
vector<int> a(t);
vector<vector<int> > dp(41, vector<int>(2, 0));
for (int i = 0; i < t; i++)
{
cin >> a[i];
if (max < a[i]) max = a[i];
}
dp[0][0] = 1;
dp[0][1] = 0;
dp[1][0] = 0;
dp[1][1] = 1;
for (int i = 2; i <= max; i++)
{
dp[i][0] = dp[i - 2][0] + dp[i - 1][0];
dp[i][1] = dp[i - 2][1] + dp[i - 1][1];
}
for (int i = 0; i < t; i++)
{
cout << dp[a[i]][0] << " " << dp[a[i]][1] << "\n";
}
return 0;
}
반응형
'이론 > 코딩테스트' 카테고리의 다른 글
[백준] 1806번 부분합 (투포인터 알고리즘) (0) | 2022.07.29 |
---|---|
[백준] 2003번 수들의 합 2 (투포인터 알고리즘) (0) | 2022.07.29 |
[백준] 11724번 연결 요소의 개수 (DFS) (0) | 2022.07.28 |
[백준] 2606번 바이러스 (DFS) (0) | 2022.07.28 |
[백준] 1010번 다리놓기 (동적 계획법/Dynamic Programming) (0) | 2022.07.28 |