μ€λμ μκ³ λ¦¬μ¦ λ¬Έμ λ λ무 μ½κ² ν΄κ²°ν΄μ μ’λ€..γ
λ¬Έμ λ₯Ό 보μνλ, μ΄λ€ μνμ μΈ μμ΄ μ‘΄μ¬ν κ² κ°μ 보μ΄μ§λ μμλ€. κ·Έλμ κ° νμ κ°μ μ§μ μ μ΄λ³΄λ κ·μΉμ λ°λ‘ λ°κ²¬ν μ μμλ€.
dp[1] = 1
dp[2] = 1
dp[3] = 1
dp[4] = 2
dp[5] = 2
dp[6] = 3 ( 1 + 2)
dp[7] = 4 (1 + 3)
dp[8] = 5 (1 + 4)
dp[9] = 7 (2 + 5)
dp[10] = 8 (2 + 7)
dp[11] = 12 (3 + 9)
dp[12] = 16 ( 4 + 12)
μ μ΄λ΄λ €κ°λ€λ³΄λ, μ λΉ¨κ°μμΌλ‘ νμν μ«μλ€μ΄ λμ λ무 λμλ€.
dp[6]λΆν° dp[1]μ΄ λν΄μ§κΈ° μμνλ€λ μ¬μ€μ μμλ€. μ¦,
dp[1] = 1
dp[2] = 1
dp[3] = 1
dp[4] = 2
dp[5] = 2
dp[6] = 3 ( 1 + 2) = dp[6-5] + dp[5]
dp[7] = 4 (1 + 3) = dp[7-5] + dp[5]
dp[8] = 5 (1 + 4) = dp[8-5] + dp[5]
dp[9] = 7 (2 + 5) = dp[9-5] + dp[5]
dp[10] = 8 (2 + 7) = dp[10-5] + dp[5]
dp[11] = 12 (3 + 9) = dp[11-5] + dp[5]
dp[12] = 16 ( 4 + 12) = dp[12-5] + dp[5]
μ΅μ’ μ μΌλ‘ dp[i] = dp[i-5] + dp[i-1] κ° λλ€λ μ¬μ€μ μμλ€.
κ·Έλ¦¬κ³ dp λ°°μ΄μ μμ±ν λ, int λ°°μ΄λ‘ μμ±νλ©΄ μ€λ²νλ‘μ°κ° λ°μν μ μμΌλ―λ‘ long λ°°μ΄λ‘ μμ±ν΄μΌ νλ€λ κ²μ μ£Όμνμ.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.valueOf(br.readLine());
long[] dp = new long[101];
dp[1]=1;dp[2]=1;dp[3]=1;
dp[4]=2;dp[5]=2;
for(int i=6;i<=100;i++) {
dp[i]=dp[i-5]+dp[i-1];
}
for(int i=1;i<=T;i++) {
System.out.println(dp[Integer.valueOf(br.readLine())]);
}
}
}