[백준] 9095번 1, 2, 3 더하기 (C++) - 간단한 dp
2023. 3. 22. 19:12
카테고리 없음
1. 발상 간단한 dp를 이용해 문제를 해결했다. i의 합 -> (i-1)의 합 + (i-2) 의 합 + (i-3) 의 합 base case -> (dp[1] = 1, dp[2] =2, dp[3] = 4) 로 설정한다. 2. 소스코드 #include #include #include using namespace std; int dp[12] = {0, }; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int T; cin >> T; dp[1] = 1; dp[2] = 2; dp[3] = 4; for(int i=4; i N; cout