[boj][c++] 6603 로또

ppparkta·2022년 9월 28일
1

Problem solving

목록 보기
42/65

6603 로또

N과 M문제를 생각나게 했던 문제다. 거의 유사하다고 본다. 재귀함수 연습하는 기분으로 풀었다.

#include	<iostream>
#include	<algorithm>
using namespace std;

int n;
int arr[14];
int depth[7];
bool check[50];

void rec(int idx, int number)
{
	if (idx == 6)
	{
		for (int i = 0; i < 6; i++)
			cout << depth[i] << " ";
		cout << '\n';
		return ;
	}
	for (int i = 0; i < n; i++)
	{
		int tmp = arr[i];
		if (check[tmp] == true)
			continue;
		if (depth[idx - 1] > tmp)
			continue;
		check[tmp] = true;
		depth[idx] = tmp;
		rec(idx + 1, number);
		check[tmp] = false;
	}
}

int main()
{
	n = -1;
	while (1)
	{
		cin >> n;
		if (n == 0)
			return 0;
		for (int i = 0; i < n; i++)
			cin >> arr[i];
		sort(arr, arr + n);
		rec(0, 0);
		cout << '\n';
	}
}
profile
겉촉속촉

0개의 댓글