File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ public class Main {
4+
5+ static int n ;
6+ static int max = Integer .MIN_VALUE ;
7+ static List <Integer > list ;
8+ static List <Integer > maxList ;
9+
10+ public static void main (String [] args ) {
11+
12+ Scanner sc = new Scanner (System .in );
13+
14+ n = sc .nextInt ();
15+
16+ solve ();
17+
18+ }
19+
20+ public static void solve () {
21+ first (n );
22+
23+ System .out .println (max );
24+
25+ for (int num : maxList ) {
26+ System .out .print (num + " " );
27+ }
28+ }
29+
30+ public static void first (int n ) {
31+ // 두번째 수 구하기
32+ for (int i = 1 ; i <= n ; i ++) {
33+ list = new ArrayList <>();
34+ list .add (n );
35+ list .add (i );
36+ dfs (n , i );
37+ }
38+
39+ }
40+
41+ public static void dfs (int before , int current ) {
42+
43+ int next = before - current ;
44+
45+ if (next < 0 ) {
46+ if (max < list .size ()) {
47+ max = list .size ();
48+ maxList = new ArrayList <>(list );
49+ }
50+ return ;
51+ }
52+
53+ // 세번째 수 ~ ?번째수까지 구하기
54+ list .add (next );
55+ dfs (current , next );
56+
57+ }
58+
59+ }
You can’t perform that action at this time.
0 commit comments