[다이나믹프로그래밍] 백준 : 이친수(2193번)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
댓글
댓글 쓰기