[다이나믹프로그래밍] 백준 : 이친수(2193번)

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
if(N > 1) {
long[] dp = new long[N+1];
dp[1] = 1;
dp[2] = 1;
for(int i = 3; i<N+1; i++)
dp[i] = sum(dp, i-2)+1;
System.out.print(dp[N]);
}
else
System.out.println(1);
}
public static long sum(long[] arr, int count) {
long result = 0;
for(int i = 1; i<=count; i++)
result += arr[i];
return result;
}
}
view raw Main.java hosted with ❤ by GitHub

댓글

가장 많이 본 글