Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created March 22, 2020 16:38
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/86df559d452480c05ff57d6f7212ff08 to your computer and use it in GitHub Desktop.
Save niklasjang/86df559d452480c05ff57d6f7212ff08 to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][1759][암호 만들기]방법1
#include <iostream>
#include <algorithm>
using namespace std;
int n=0, k=0;
int mo=0, za=0;
char input[20];
char arr[100];
bool visited[20];
void recur(int depth, int start, int mcnt, int zcnt){
if(depth == n){
if(mcnt >= 1 && zcnt >=2){
for(int i=0; i<n; i++){
cout << arr[i];
}
cout<<'\n';
}
return;
}
for(int i=start; i<k; i++){
if(visited[i]) continue;
arr[depth] = input[i];
visited[i] = true;
if(input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u'){
recur(depth+1, i+1, mcnt+1, zcnt);
}else{
recur(depth+1, i+1, mcnt, zcnt+1);
}
visited[i] = false;
}
}
int main (void){
cin.tie(NULL);
ios::sync_with_stdio("false");
cin>> n >> k;
for(int i=0; i<k; i++){
cin >> input[i];
}
sort(input, input+k);
recur(0, 0, 0, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment