-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDP13ArrangeBuildingDP.java
More file actions
48 lines (28 loc) · 908 Bytes
/
Copy pathDP13ArrangeBuildingDP.java
File metadata and controls
48 lines (28 loc) · 908 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
import java.util.*;
public class DP13ArrangeBuildingDP{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
// int dpBuilding[]= new int[n+1];
// int dpSpace[]= new int[n+1];
// dpBuilding[2]=1;
// dpSpace[2]=1;
// for(int i = 2 ; i <=n ; i++){
// dpBuilding[i]= dpSpace[i-1];
// dpSpace[i]= dpBuilding[i-1]+dpSpace[i-1];
// }
// System.out.println((dpBuilding[n]+dpSpace[n] ) * (dpBuilding[n]+dpSpace[n] ) );
/// other way
int olderbuilding = 1 ;
int olderspace = 1 ;
for(int i = 2 ; i <=n ; i++){
int newBuilding= olderspace;
int newSpace = olderbuilding + olderspace;
olderbuilding = newBuilding;
olderspace = newSpace;
}
int total = olderbuilding+ olderspace;
total=total*total;
System.out.println(total);
}
}