그럴듯한 개발 블로그
반응형

https://www.acmicpc.net/problem/1759

 

1759번: 암호 만들기

첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.

www.acmicpc.net

for (int i = depth; i < num; i++)
dfs(cur + s[i], i + 1);

dfs 두 번째 인자로 i 넣어야 한다 depth랑 헷갈 ㄴ

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <unordered_set>
#include <cstring>
#include <utility>

using namespace	std;

int len, num;
string s, moum = "aeiou";

void dfs(string cur, int depth) {
	if (cur.size() == len) {
		int moumCnt = 0;
		for (int i = 0; i < len; i++)
			for (int j = 0; j < 5; j++)
				if (moum[j] == cur[i])
					moumCnt++;
		if (moumCnt != 0 && len - moumCnt >= 2)
			cout << cur << '\n';
		return ;
	}
	for (int i = depth; i < num; i++)
		dfs(cur + s[i], i + 1);
}

int	main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> len >> num;
	for (int i = 0; i < num; i++) {
		char input;
		cin >> input;
		s += input;
	}
	sort(s.begin(), s.end());
	dfs("", 0);
}
반응형

'<algorithm> > 백준' 카테고리의 다른 글

백준 2217 로프 c++  (0) 2023.10.05
백준 11559 Puyo Puyo c++  (1) 2023.10.01
백준 2195 문자열 복사 c++  (0) 2023.09.23
백준 11047 동전 0 c++  (0) 2023.09.23
백준 15686 치킨 배달 c++  (0) 2023.09.22
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!