Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOJ_15663_N과 M(9) #48

Open
changicho opened this issue Jan 10, 2020 · 0 comments
Open

BOJ_15663_N과 M(9) #48

changicho opened this issue Jan 10, 2020 · 0 comments
Labels
not clear 진행중인 코드
Milestone

Comments

@changicho
Copy link
Owner

15663. N과 M(9)

링크

난이도 정답률(_%)
Silver II 47

설계

정리

내 코드 빠른 코드

고생한 점

코드

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> nums;
vector<string> answers;
int N, M;

bool visited[8] = { false, };

void dfs(int answer_count, string answer) {
	if (answer_count == M) {
		answers.push_back(answer);
		return;
	}

	for (int i = 0; i < N; i++) {
		if (visited[i]) continue;

		visited[i] = 1;
		string new_answer = answer + to_string(nums[i]) + " ";
		dfs(answer_count + 1, new_answer);
		visited[i] = 0;
	}	
}

void solution() { 
	cin >> N >> M;

	nums.resize(N);
	for (int i = 0; i < N; i++) cin >> nums[i];

	vector<int> answer;

	dfs(0, "");

	sort(answers.begin(), answers.end());

	answers.erase(unique(answers.begin(), answers.end()), answers.end());

	for (string a : answers) {
		cout << a << "\n";
	}

	//cout << "\n"; 
}

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

	solution();

	return 0;
}
@changicho changicho added the not clear 진행중인 코드 label Jan 10, 2020
@changicho changicho added this to the day5 milestone Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not clear 진행중인 코드
Projects
None yet
Development

No branches or pull requests

1 participant