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 | #include <stdio.h> int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); if (n == 1) { printf("1\n"); continue; } else if (n == 2) { printf("2\n"); continue; } else if (n == 3) { printf("4\n"); continue; } long long a = 1, b = 2, c = 4, rst; for (int i = 4; i <= n; i++) { rst = a + b + c; a = b; b = c; c = rst; } printf("%lld\n", rst); } } | cs |
'알고리즘 > DP' 카테고리의 다른 글
1003 피보나치 함수 (0) | 2019.07.05 |
---|---|
2579 계단오르기 (0) | 2019.07.05 |
2193 이친수 (0) | 2019.07.05 |
(미해결) buy lower 더블릿 (0) | 2019.02.23 |
색종이 더블릿 (업시퀀스) (0) | 2019.02.21 |