#BOJ 9095 1,2,3 더하기

Wonder_Why (Today I learned)·2022년 2월 23일
0

BOJ

목록 보기
62/70
post-thumbnail

1,2,3 더하기 (다이나믹프로그래밍)

문제 바로가기 -> https://www.acmicpc.net/problem/9095

구현

/*
BOJ : https://www.acmicpc.net/problem/9095
DP Adding 1s, 2s, and 3s
Versatile0010
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
using namespace std;
int dp[11];


int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	freopen("input.txt", "r", stdin);
	int t, n;
	cin >> t;
	dp[1] = 1, dp[2] = 2, dp[3] = 4;
	for (int i = 4; i <= 11; i++)
	{
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
	}
	while (t--)
	{
		cin >> n;
		cout << dp[n] << '\n';
	}
	return 0;
}

GIT : https://github.com/versatile0010/Algorithm/blob/main/DP/BOJ%209095%201%2C2%2C3%20%EB%8D%94%ED%95%98%EA%B8%B0.cpp

profile
전자과 머학생

0개의 댓글