Coding Test - cpp/DP
[백준 9095 : 1, 2, 3 더하기] - C++
에드윈H
2021. 1. 15. 20:14
#include <iostream>
#include <vector>
using namespace std;
int dp[12];
int find(int n)
{
if (n == 1) return 1;
if (n == 2) return 2;
if (n == 3) return 4;
int& target = dp[n];
if (target != -1)
{
return target;
}
return target = find(n - 1) + find(n - 2) + find(n - 3);
}
int main() {
int testCase;
cin >> testCase;
while (testCase--)
{
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
cout << find(n) << endl;
}
return 0;
}