Strong Root

문제를 보시려면 여기를 클릭


이하는 코드입니다.


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
#include <stdio.h>
#include <string.h>
 
#pragma warning(disable:4996)
 
int cache[101];
 
int getCount(int n) {
    if (n == 1) {
        return 1;
    }
    if (n == 2) {
        return 2;
    }
 
    int& ret = cache[n];
    if (ret != -1) {
        return ret;
    }
 
    return ret = ((getCount(n - 1) + getCount(n - 2)) % 1000000007);
}
 
int main() {
    int C;
    scanf("%d", &C);
 
    for (int i = 0; i < C; i++) {
        int n;
        scanf("%d", &n);
 
        memset(cache, -1sizeof(cache));
        printf("%d\n", getCount(n));
    }
 
    return 0;
}
cs