Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 정렬
- 유클리드호제법
- Set
- 다이나믹프로그래밍
- 티스토리챌린지
- 분할정복
- DFS
- 오블완
- 최소공배수
- int
- 알고리즘
- 배열
- stoi
- 우선순위큐
- BFS
- N과M
- 이분탐색
- 프로그래머스
- 깊이우선탐색
- C++
- vector
- priority_queue
- DP
- map
- 문자열
- 그래프
- Sort
- 백준
- 에라토스테네스의 체
- 백트래킹
Archives
- Today
- Total
안녕 세상아,
[c++/백준] 6603 로또 본문
https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
n과 m (7) 문제랑 같은 방식으로 풀면 된다.
기존 배열과 다른 배열을 하나 더 만들어서 새로운 값을 넣어준 후 조합으로 출력해주면 된다.
#include <iostream>
#include <cstring> //memset 사용
#include <algorithm> //sort 사용
using namespace std;
int k;
bool isVisited[14] = { false };
int map[14];
int ans[14];
void dfs(int n,int x) {
if (x == 6) {
for (int i = 0; i < 6; i++) {
cout << ans[i] << " ";
}
cout << endl;
return;
}
for (int i = n; i < k; i++) {
if (!isVisited[i]) {
isVisited[i] = true;
ans[x] = map[i];
dfs(i + 1, x + 1);
isVisited[i] = false;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
while (1) {
cin >> k;
if (k == 0)
break;
for (int i = 0; i < k; i++) {
cin >> map[i];
}
sort(map, map + k); //오름차순 정렬
dfs(0, 0);
cout << endl;
memset(isVisited, false, sizeof(isVisited));
memset(map, 0, sizeof(map));
}
}
'백준' 카테고리의 다른 글
[c++/백준] 1780 종이의 개수 (0) | 2023.06.27 |
---|---|
[c++/백준] 2630 색종이 만들기 (1) | 2023.06.21 |
[c++/백준] 11508 2+1 세일 (0) | 2023.06.17 |
[c++/백준] 18870 좌표 압축 (0) | 2023.06.16 |
[c++/백준] 4963 섬의 개수 (bfs) (0) | 2023.06.15 |