forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproDP1.java
More file actions
54 lines (39 loc) · 935 Bytes
/
proDP1.java
File metadata and controls
54 lines (39 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Arrays;
public class proDP1 {
static long ArrayDp[];
public static void main(String[] args) {
int n = 6;
System.out.println(solution(n));
}
//규칙
//6 - 8*4 + 5*2
//5 - 5*4 + 3*2
//3 - 2*4 + 1*2
//1,1,2,3,5,8,13,21
public static long solution(int n) {
//계산없이 초장에 끝내기
if(n==0)
return 0;
else if(n == 1)
return 4;
else if(n==2)
return 6;
//0으로 초기화
ArrayDp = new long[n];
ArrayDp[0] = 1;
ArrayDp[1] = 1;
makeArray(ArrayDp,n);
return DP(n);
}
public static void makeArray(long[] a, int n)
{
for(int i=2; i<n; i++)
{
ArrayDp[i] = ArrayDp[i-2] + ArrayDp[i-1];
}
}
public static long DP(int n)
{
return ArrayDp[n-1]*4 + ArrayDp[n-2]*2;
}
}