File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 215
215
| 23 | | [ Baekjoon-11722 κ°μ₯ κΈ΄ κ°μνλ λΆλΆ μμ΄] ( src/DP/P11722 ) | |
216
216
| 24 | | [ Baekjoon-11054 κ°μ₯ κΈ΄ λ°μ΄ν λ λΆλΆ μμ΄] ( src/DP/P11054 ) | |
217
217
| 25 | | [ Baekjoon-1912 μ°μν©] ( src/DP/P1912 ) | |
218
+ | 26 | | [ Baekjoon-13398 μ°μν© 2] ( src/DP/P13398 ) | |
218
219
219
220
---
220
221
Original file line number Diff line number Diff line change
1
+ package DP .P13398 ;
2
+
3
+ import java .io .*;
4
+ import java .util .*;
5
+
6
+ public class Main {
7
+
8
+ static int n ;
9
+ static int [] arr ;
10
+ static int [][] dp ;
11
+
12
+ public static void main (String [] args ) throws Exception {
13
+ System .setIn (new FileInputStream ("src/DP/P13398/input.txt" ));
14
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15
+
16
+ n = Integer .parseInt (br .readLine ());
17
+ arr = new int [n ];
18
+ StringTokenizer st = new StringTokenizer (br .readLine ());
19
+ for (int i = 0 ; i < n ; i ++) {
20
+ arr [i ] = Integer .parseInt (st .nextToken ());
21
+ }
22
+
23
+ dp = new int [n ][2 ];
24
+ dp [0 ][0 ] = dp [0 ][1 ] = arr [0 ];
25
+ int max = arr [0 ];
26
+ for (int i = 1 ; i < n ; i ++) {
27
+ dp [i ][0 ] = Math .max (dp [i -1 ][0 ], 0 ) + arr [i ];
28
+ dp [i ][1 ] = Math .max (dp [i -1 ][0 ], dp [i -1 ][1 ] + arr [i ]);
29
+ max = Math .max (max , Math .max (dp [i ][0 ], dp [i ][1 ]));
30
+ }
31
+
32
+ System .out .println (max );
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ ## [ baekjoon-13398] μ°μν© 2
2
+
3
+ ![ image] ( https://user-images.githubusercontent.com/22045163/100982308-3cb2a900-358b-11eb-9cf0-37de27655ed8.png )
4
+
5
+ ### μ νμ
6
+
7
+ ``` java
8
+ dp[0 ][0 ] = dp[0 ][1 ] = arr[0 ];
9
+ dp[n][0 ] = Math . max(dp[n- 1 ][0 ], 0 ) + arr[n];
10
+ dp[n][1 ] = Math . max(dp[n- 1 ][0 ], dp[n- 1 ][1 ] + arr[n]);
11
+ ```
12
+
13
+ ![ IMG_BEB4BBF853D3-1] ( https://user-images.githubusercontent.com/22045163/100983690-00804800-358d-11eb-81a9-2f0c46161d57.jpeg )
14
+
15
+ νμ.. νμ°Έμ ν€λ§¨ λ¬Έμ λ€. μ±μ₯νμ !!!
Original file line number Diff line number Diff line change
1
+ 5
2
+ -10 10 20 -40 50
3
+
4
+ 10
5
+ 2 1 -4 3 4 -4 6 5 -5 1
6
+
7
+ 10
8
+ 10 -4 3 1 5 6 -35 12 21 -1
9
+
10
+ 5
11
+ -1 -2 -3 -4 -5
You canβt perform that action at this time.
0 commit comments