[BOJ] 9095 1, 2, 3 더하기

Time Lapse :NONE

9095.c

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
32
33
34
35
36
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 20

int n;
int cache[MAXSIZE];
int testcase[MAXSIZE];

int main(void)
{
cin >> n;
memset(cache, -1, sizeof(cache));
cache[1] = 1;
cache[2] = 2;
cache[3] = 4;
for (int i = 4; i <= 11; i++)
{
cache[i] = cache[i - 1] + cache[i - 2] + cache[i - 3];
}
for (int i = 0; i < n; i++)
{
cin >> testcase[i];
}
for (int i = 0; i < n; i++)
{
cout << cache[testcase[i]] << endl;;
}
}

9095.cpp

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
32
33
34
35
36
37
38
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 20

int n;
int cache[MAXSIZE];
int testcase[MAXSIZE];

int main(void)
{
cin >> n;
memset(cache, -1, sizeof(cache));
cache[1] = 1;
cache[2] = 2;
cache[3] = 4;
for (int i = 4; i <= 11; i++)
{
cache[i] = cache[i - 1] + cache[i - 2] + cache[i - 3];
}
for (int i = 0; i < n; i++)
{
cin >> testcase[i];
}
for (int i = 0; i < n; i++)
{
cout << cache[testcase[i]] << endl;;
}


}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/9095/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.