BOJ 15649: N과 M (1)

문제

#include <iostream>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX]; int arr[MAX];

void go(int idx) { // dfs
	if (idx == M) {
		for (int i = 0; i < M; i++) cout << arr[i] << " ";
		cout << "\n";
		return;
	}

	for (int i = 1; i <= N; i++) {
		if (!check[i]) {
			check[i] = true;
			arr[idx] = i;
			go(idx + 1);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	go(0);

	return 0;
}

BOJ 15650: N과 M (2)

문제

#include <iostream>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX];
int arr[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << arr[i] << " ";
		cout << "\n";
		return;
	}

	for (int i = start; i <= N; i++) {
		if (!check[i]) {
			check[i] = true;
			arr[idx] = i;
			go(idx + 1, i + 1);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	go(0, 1);

	return 0;
}

BOJ 15651: N과 M (3)

문제

#include <iostream>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];

void go(int idx) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << arr[i] << " ";
		cout << "\n";
		return;
	}

	for (i = 1; i <= N; i++) {
		arr[idx] = i;
		go(idx + 1);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	go(0);

	return 0;
}

BOJ 15652: N과 M (4)

문제

#include <iostream>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << arr[i] << " ";
		cout << "\n";
		return;
	}

	for (i = start; i <= N; i++) {
		arr[idx] = i;
		go(idx + 1, i);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	go(0, 1);

	return 0;
}

BOJ 15654: N과 M (5)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX];
int arr[MAX];
int num[MAX];

void go(int idx) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	for (i = 0; i < N; i++) {
		if (!check[i]) {
			check[i] = true;
			arr[idx] = i;
			go(idx + 1);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0);

	return 0;
}

BOJ 15655: N과 M (6)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX];
int arr[MAX];
int num[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	for (i = start; i < N; i++) {
		if (!check[i]) {
			check[i] = true;
			arr[idx] = i;
			go(idx + 1, i);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0, 0);

	return 0;
}

BOJ 15656: N과 M (7)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];
int num[MAX];

void go(int idx) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	for (i = 0; i < N; i++) {
		arr[idx] = i;
		go(idx + 1);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0);

	return 0;
}

BOJ 15657: N과 M (8)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];
int num[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	for (i = start; i < N; i++) {
		arr[idx] = i;
		go(idx + 1, i);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0, 0);

	return 0;
}

BOJ 15663: N과 M (9)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX];
int arr[MAX];
int num[MAX];

void go(int idx) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	int prev = -1;

	for (i = 0; i < N; i++) {
		if (!check[i] && prev != num[i]) {
			check[i] = true;
			arr[idx] = i;
			prev = num[i];
			go(idx + 1);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0);

	return 0;
}

BOJ 15664: N과 M (10)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
bool check[MAX];
int arr[MAX];
int num[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	int prev = -1;

	for (i = start; i < N; i++) {
		if (!check[i] && prev != num[i]) {
			check[i] = true;
			arr[idx] = i;
			prev = num[i];
			go(idx + 1, i);
			check[i] = false;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0, 0);

	return 0;
}

BOJ 15665: N과 M (11)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];
int num[MAX];

void go(int idx) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	int prev = -1;

	for (i = 0; i < N; i++) {
		if (prev != num[i]) {
			arr[idx] = i;
			prev = num[i];
			go(idx + 1);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0);

	return 0;
}

BOJ 15666: N과 M (12)

문제

#include <iostream>
#include <algorithm>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];
int num[MAX];

void go(int idx, int start) {
	int i;

	if (idx == M) {
		for (i = 0; i < M; i++) cout << num[arr[i]] << " ";
		cout << "\n";
		return;
	}

	int prev = -1;

	for (i = start; i < N; i++) {
		if (prev != num[i]) {
			arr[idx] = i;
			prev = num[i];
			go(idx + 1, i);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> num[i];
	sort(num, num + N);
	go(0, 0);
            
	return 0;
}