페이지

9095번: 1, 2, 3 더하기

https://www.acmicpc.net/problem/9095


$O(t)$

dp[0]=dp[1]=1 dp[2]=2
dp[n]=dp[n-1]+dp[n-2]+d[n-3]


#include<cstdio>
int t, a[11] = { 1,1,2 }, n;
int main() {
    for (int i = 3; i <= 10; i++) a[i] = a[i - 1] + a[i - 2] + a[i - 3];
    scanf("%d", &t);
    while (t--) scanf("%d", &n), printf("%d\n", a[n]);
    return 0;
}

댓글 없음 :

댓글 쓰기