Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Last active March 22, 2020 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasjang/5bcc97fe2a1ba1b41dd1f14c2e4ba1ba to your computer and use it in GitHub Desktop.
Save niklasjang/5bcc97fe2a1ba1b41dd1f14c2e4ba1ba to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][15651][N과 M (7)]
#include <iostream>
#include <algorithm>
using namespace std;
int n=0, k=0;
int input[100];
int arr[100];
void recur(int depth){
if(depth == n){
for(int j=0; j<n; j++){
cout << arr[j] <<" ";
}
cout<<"\n";
return;
}
for(int i=0; i<k; i++){
arr[depth] = input[i];
recur(depth+1);
}
}
int main (void){
cin.tie(NULL);
ios::sync_with_stdio("false");
cin>> k>> n;
for(int i=0; i<k;i++){
cin >> input[i];
}
sort(input, input+k);
recur(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment