-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package 인프런.Section07; | ||
|
||
import java.util.Scanner; | ||
|
||
public class 부분집합_DFS { | ||
static int n; | ||
static int[] ch; | ||
|
||
public void DFS(int L) { | ||
if(L == n+1) { | ||
String tmp = ""; | ||
for(int i = 1; i <= n; i++) { | ||
if(ch[i] == 1) tmp += (i + " "); | ||
} | ||
if (tmp.length() > 0) { | ||
System.out.println(tmp); | ||
} | ||
} else { | ||
ch[L] = 1; //부분집합에 포함하는 경우 | ||
DFS(L+1); | ||
ch[L] = 0; //부분집합에 포함하지 않는 경우 | ||
DFS(L+1); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
부분집합_DFS t = new 부분집합_DFS(); | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
|
||
n = scanner.nextInt(); | ||
ch = new int[n+1]; | ||
|
||
t.DFS(1); | ||
} | ||
} |