문제

https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
코드
#include <iostream>
using namespace std;
int arr[12];
int lotto[6];
int t;
void dfs(int num, int cnt){
if(cnt==6){
for(int i=0; i<6; i++){
cout << lotto[i] << ' ';
}
cout << '\n';
return;
}
for(int i=num; i<t; i++){
lotto[cnt] = arr[i];
dfs(i+1, cnt+1);
}
}
int main(){
while(true){
cin >> t;
if(t==0) break;
for(int i=0; i<t; i++){
cin >> arr[i];
}
dfs(0, 0);
cout << '\n';
}
return 0;
}
정리
15655번(https://kdongree.tistory.com/85) 문제와 매우 유사하다.
중복x, 오름차순을 요구하는 문제는 위 문제처럼 풀 것을 기억해야겠다.
참조
'Beakjoon > backtracking' 카테고리의 다른 글
| [백준] 10819번 차이를 최대로 (C++) - backtracking (0) | 2022.05.21 |
|---|---|
| [백준] 18290번 NM과 K (1) (C++) - backtracking (0) | 2022.04.26 |
| [백준] 15657번 N과 M (8) (C++) - backtracking (0) | 2022.04.15 |
| [백준] 15656번 N과 M (7) (C++) - backtracking (0) | 2022.04.15 |
| [백준] 15655번 N과 M (6) (C++) - backtracking (0) | 2022.04.15 |