File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Dynamic_programming/problem solving Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #define MAX 1001
3
+
4
+ using namespace std ;
5
+
6
+ int n;
7
+ int boxArr[MAX];
8
+ int d[MAX];
9
+
10
+ void init () {
11
+ for (int i = 0 ; i < n; i++) {
12
+ cin >> boxArr[i];
13
+ }
14
+
15
+ // 모든 박스는 일단 1개로 취급
16
+ for (int i = 0 ; i < n; i++) {
17
+ d[i] = 1 ;
18
+ }
19
+ }
20
+
21
+ void dp () {
22
+
23
+ for (int i = 0 ; i < n; i++) {
24
+ for (int j = 0 ; j < i; j++) {
25
+ if (boxArr[i] > boxArr[j]) {
26
+ d[i] = (d[i] < d[j] + 1 ) ? d[j] + 1 : d[i];
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ int main () {
33
+ ios::sync_with_stdio (false );
34
+ cin.tie (NULL );
35
+ cout.tie (NULL );
36
+
37
+ cin >> n;
38
+
39
+ init ();
40
+ dp ();
41
+
42
+ int maxResult = 1 ;
43
+
44
+ for (int i = 0 ; i < n; i++) {
45
+ maxResult = (maxResult > d[i]) ? maxResult : d[i];
46
+ }
47
+
48
+ cout << maxResult;
49
+
50
+ return 0 ;
51
+ }
You can’t perform that action at this time.
0 commit comments