• Home
  • About
    • 코드좀비 photo

      코드좀비

      An amazing website.

    • Learn More
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[BOJ] 백준 15665 N과M (11) 간단한설명과 코드 C++

15 Mar 2020

Reading time ~1 minute

문제 정보

백준 ( BOJ ) 15665 N과M (11)

문제 풀이 : 수열

문제 출처 : https://www.acmicpc.net/problem/15665

N과 M 문제 종합 보기 : https://mountrivers.github.io/bsequence/

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

using namespace std;

int n, m;
int base;
vector<int> v(8, 0);
vector<int> result;
unordered_set<string> checker;
void fun(int roopedTime) {
	if (roopedTime == m) {
		string temp;
		for (int i = 0; i < m; i++) {
			temp += to_string(result[v[i]]) + " ";
		}
		auto itr = checker.find(temp);
		if (itr == checker.end()) {
			checker.insert(temp);
			for (int i = 0; i < m; i++) {
				printf("%d ", result[v[i]]);
			}
			printf("\n");

		}
	}
	else {
		for (int i = 0; i < n; i++) {
				v[roopedTime] = i;
				fun(roopedTime + 1);
			
		}
	}
}

int main() {
	int temp;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		result.push_back(temp);
	}
	sort(result.begin(), result.end());
	fun(0);


	return 0;
}


백준C++수열 Share Tweet +1