티스토리 뷰

백준

백준 소스코드 [C++] 6603 로또

Hani_Levenshtein 2020. 12. 19. 22:35

www.acmicpc.net/problem/6603

 

6603번: 로또

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로

www.acmicpc.net

백준 소스코드 [C++] 6603 로또

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;
#define all(v) v.begin(),v.end()
int arr[13];
bool check[13];
vector <int> v;
int n;
void dfs(int x) {
	if (x == 6) {
		for (int i = 0;i < x;i++) cout << v[i] << " ";
		cout << '\n';
		return;
	}
	for (int i = 0;i < n;i++)
		if (check[i] == false && (v.empty()==true || (v.back()<arr[i]))) {
			check[i] = true;
			v.push_back(arr[i]);
			dfs(x+1);
			v.pop_back();
			check[i] = false;
		}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	while (true) {
		cin >> n;
		if (n == 0) break;
		for (int i = 0;i < n;i++) cin >> arr[i];
		memset(check, false, sizeof(check));
		dfs(0);
		cout << '\n';
	}
	return 0;
}
댓글