File tree Expand file tree Collapse file tree 4 files changed +179
-0
lines changed
src/main/java/sgyj/backjun/yeji Expand file tree Collapse file tree 4 files changed +179
-0
lines changed Original file line number Diff line number Diff line change
1
+ package sgyj .backjun .yeji ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+ import java .util .Arrays ;
7
+
8
+ // 부분수열의 합
9
+ public class Main1182 {
10
+
11
+ private static int [] data ;
12
+ private static int target ;
13
+ private static int answer ;
14
+ private static int N ;
15
+
16
+ public static void main ( String [] args ) throws IOException {
17
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ) );
18
+ int [] input = Arrays .stream (br .readLine ().split ( " " )).mapToInt ( Integer ::parseInt ).toArray ();
19
+ data = Arrays .stream ( br .readLine ().split ( " " ) ).mapToInt ( Integer ::parseInt ).toArray ();
20
+ target = input [1 ];
21
+ N = input [0 ];
22
+
23
+ dfs (0 ,0 );
24
+
25
+ System .out .println (target == 0 ? answer - 1 : answer );
26
+ }
27
+
28
+ private static void dfs (int dep , int sum ) {
29
+ if (dep == N ) {
30
+ if (sum == target )
31
+ answer ++;
32
+ return ;
33
+ }
34
+
35
+ dfs (dep + 1 , sum + data [dep ]);
36
+ dfs (dep + 1 , sum );
37
+ }
38
+
39
+
40
+
41
+ }
Original file line number Diff line number Diff line change
1
+ package sgyj .backjun .yeji ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+
7
+
8
+ // N과 M (1)
9
+ public class Main15649 {
10
+ // N : 1 부터 N까지의 수
11
+ // M : 조합의 갯수
12
+ private static boolean [] visited ;
13
+ private static int [] data ;
14
+ private static int N ,M ;
15
+
16
+ public static void solution (){
17
+ for (int i =1 ; i <=N ; i ++){
18
+ visited [i ] = true ;
19
+ data [0 ] = i ;
20
+ dfs (1 );
21
+ data [0 ] = 0 ;
22
+ visited [i ] = false ;
23
+ }
24
+ }
25
+
26
+ public static void dfs ( int L ){
27
+ if (L == M ){
28
+ for (int i =0 ; i <data .length ; i ++){
29
+ if (data [i ] != 0 ){
30
+ System .out .print (data [i ] + " " );
31
+ }
32
+ }
33
+ System .out .println ();
34
+ }else {
35
+ for (int j =1 ; j <=N ; j ++){
36
+ if (!visited [j ] ){
37
+ visited [j ] = true ;
38
+ data [L ] = j ;
39
+ dfs (L +1 );
40
+ data [L ] = 0 ;
41
+ visited [j ] = false ;
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ public static void main ( String [] args ) throws IOException {
48
+ BufferedReader br = new BufferedReader ( new InputStreamReader ( System .in ) );
49
+ String [] s = br .readLine ().split ( " " );
50
+ N = Integer .parseInt ( s [0 ] );
51
+ M = Integer .parseInt ( s [1 ] );
52
+ visited = new boolean [N +1 ];
53
+ data = new int [N +1 ];
54
+ solution ();
55
+ }
56
+
57
+ }
Original file line number Diff line number Diff line change
1
+ package sgyj .backjun .yeji ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+ import java .util .StringTokenizer ;
7
+
8
+ // N과M (2)
9
+ public class Main15650 {
10
+
11
+ public static int [] arr ;
12
+ public static int N , M ;
13
+ public static StringBuilder sb = new StringBuilder ();
14
+
15
+ public static void main (String [] args ) throws IOException {
16
+
17
+ BufferedReader br = new BufferedReader ( new InputStreamReader ( System .in ));
18
+ StringTokenizer st = new StringTokenizer ( br .readLine ());
19
+
20
+ N = Integer .parseInt (st .nextToken ());
21
+ M = Integer .parseInt (st .nextToken ());
22
+
23
+ arr = new int [M ];
24
+
25
+ dfs (1 , 0 );
26
+ System .out .println (sb );
27
+
28
+ }
29
+
30
+ public static void dfs (int at , int depth ) {
31
+
32
+ if (depth == M ) {
33
+ for (int val : arr ) {
34
+ sb .append (val ).append (' ' );
35
+ }
36
+ sb .append ('\n' );
37
+ return ;
38
+ }
39
+
40
+ for (int i = at ; i <= N ; i ++) {
41
+
42
+ arr [depth ] = i ;
43
+ dfs (i + 1 , depth + 1 );
44
+
45
+ }
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ package sgyj .backjun .yeji ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+ import java .util .Arrays ;
7
+
8
+ // 2920 : 음계
9
+ public class Main2920 {
10
+
11
+ public static void main ( String [] args ) throws IOException {
12
+ BufferedReader br = new BufferedReader ( new InputStreamReader ( System .in ) );
13
+ int [] s = Arrays .stream ( br .readLine ().split ( " " ) ).mapToInt ( Integer ::parseInt ).toArray ();
14
+ int [] compare = Arrays .copyOf ( s , s .length );
15
+ Arrays .sort ( compare );
16
+ if (Arrays .compare ( s ,compare ) == 0 ){
17
+ System .out .println ("ascending" );
18
+ }else {
19
+ boolean flag = false ;
20
+ for (int i =0 ; i <s .length ; i ++){
21
+ if (s [i ] != compare [s .length -i -1 ]){
22
+ System .out .println ("mixed" );
23
+ flag = true ;
24
+ break ;
25
+ }
26
+ }
27
+
28
+ if (!flag ){
29
+ System .out .println ("descending" );
30
+ }
31
+ }
32
+
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments