쉬운 백트레킹 문제입니다.
실수 할 수 있는점은
자음, 모음의 최소 개수가 정해져 있다는점과
입력을 받을때 실수 하지 말아야 한다는 점입니다.
#include <iostream> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <queue> #include <set> #include <utility> #include <functional> #define MAX 75005 #define INF 987654321 #define MOD 1000000007 #pragma warning(disable:4996) using namespace std; int n,m; char arr[20],ans[20],str[10]="aeiou"; bool tf; void back(int cur,int cnt, int mo, int ja) { if(cnt>n) return; for(int i=cur;i<m;i++) { int tmp_mo=mo,tmp_ja=ja; ans[cnt]=arr[i]; tf=false; for(int k=0;k<5;k++) if(ans[cnt]==str[k]) tf=true; if(tf) tmp_mo++; else tmp_ja++; if(n==cnt&&tmp_mo>=1&&tmp_ja>=2) printf("%s\n",ans+1); else back(i+1,cnt+1,tmp_mo,tmp_ja); } } int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;i++) scanf(" %c",&arr[i]); sort(arr,arr+m); back(0,1,0,0); return 0; }
'IT > BOJ' 카테고리의 다른 글
백준(BOJ) 1946 신입사원 * (0) | 2018.06.01 |
---|---|
백준(BOJ) 2629 부등호 * (0) | 2018.06.01 |
백준(BOJ) 1720번 타일 코드 *** (0) | 2018.06.01 |
백준(BOJ) 14501 퇴사 * (0) | 2018.06.01 |
백준(BOJ) 1126 같은 탑 *** (0) | 2018.06.01 |