ν¨ν΄μ νμ νκΈ° μν΄μ νΈλ¦¬κ΅¬μ‘°λ‘ κ·Έλ €λ³΄μλ€.
κ·Έλ¬λλ, μμ κ°μ΄ νμ ν μ μμκ³ , νΌλ³΄λμΉ μμ΄μ΄κ΅¬λ κΉ¨λ¬μλ€.
Dp[1] = 1
Dp[2] = 1
Dp[3] = 2
Dp[4] = 3
Dp[5] = 5
κ²½μ°μ μλ₯Ό μ μ΄λ³΄κΈ°λ§ νμ΄λ, νΌλ³΄λμΉμμ μμΈ‘νμ κ² κ°λ€..γ γ
μλ¬΄νΌ Dp[i] = Dp[i-1]+Dp[i-2] μ νμμ μ¬μ©νλ©΄ λ¬Έμ λ λ§€μ° κ°λ¨νκ² ν΄κ²°λλ€!
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
long [] Dp = new long[N+2];
Dp[1]=1;
Dp[2]=1;
for(int i=3;i<=N;i++) {
Dp[i]=Dp[i-1]+Dp[i-2];
}
System.out.println(Dp[N]);
}
}
λ°μ΄ν°κ° μ€λ²νλ‘μ°κ° λ°μν μ μκΈ° λλ¬Έμ long νμ μ Dpλ₯Ό μμ±νλκ² μ€μνλ€.