Posts 9095 1,2,3 더하기
Post
Cancel

9095 1,2,3 더하기

9095 1,2,3 더하기

코드

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
#include <iostream>

using namespace std;

int tc;
long long save[12];

long long dp(int n);

int main() {
	cin >> tc;

	while (tc--) {
		int n;
		cin >> n;
		cout << dp(n) << endl;
	}
}

long long dp(int n) {
	if (n < 0)
		return 0;
	if (n == 0) {
		return 1;
	}
	if (save[n] != 0)
		return save[n];

	return save[n] = dp(n - 3) + dp(n-2) + dp(n-1);

}
This post is licensed under CC BY 4.0 by the author.

5373 Samsung sw test

13303 장애물 경기

Comments powered by Disqus.