| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- android adapterview
- 깊이우선탐색
- 백준 알고리즘
- java
- 백준
- 안드로이드 ANR
- 너비우선탐색
- application not responding
- support fragment
- support 라이브러리
- SQLite와 Realm 차이점
- 컬렉션
- BFS
- 안드로이드 DBMS
- android support
- 알고리즘
- db
- oracle
- 안드로이드
- DFS
- 소수 알고리즘
- 소수
- 안드로이드 파일
- 안드로이드 AdapterView
- 자바 컬렉션
- 자료구조
- 액티비티 ANR
- Github
- anr
- android fragment
													Archives
													
											
												
												- Today
- Total
밍의 기록들😉
[문제] 이진 패턴 본문
문제
소스코드
import java.util.Scanner;
public class Tobin {
	private static int N;
	private static int K;
	public static int[] ans = new int[30];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		tobin(N, K, 0);
	}
	// n자릿수 1이 k개인 경우의 수 
	private static void tobin(int n, int k, int index) {
		if(N == index){ // 인덱스가 자릿수만큼 채워질 경우 출력
			for(int i=0; i<index; i++){
				System.out.print(ans[i]);
			}
			System.out.println();
			return;
		}
		else{ // 처음 시작은 1_ _ _ 경우와 0_ _ _ 인 경우로 생각
			if(k>0){ 
				ans[index] = 1;
				tobin(n-1, k-1, index+1);
			}
			if(n-k >0){ // 자리수 - 1의 갯수
				ans[index] = 0;
				tobin(n-1, k, index+1);
			}
		}
	}
}
풀이
주석의 설명만으로도 충분할 것 같아 생략 한다 !
'자료구조, 알고리즘 > 문제풀이' 카테고리의 다른 글
| [문제] 부등호 2529번 (0) | 2018.09.05 | 
|---|---|
| [문제] 웜바이러스 2606번 (0) | 2018.09.05 | 
| [문제] 자연수의 분할 (4) | 2018.09.04 | 
| [문제] 단지번호 붙이기 2667번 (0) | 2018.08.27 | 
| [문제] 분수 합 1735번 (0) | 2018.08.16 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				