알고리즘 문제/BOJ
6603번 로또
parkit
2018. 8. 30. 00:56
728x90
반응형
기본적인 백트래킹 문제다.
https://www.acmicpc.net/problem/6603
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <iostream> #include <queue> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> using namespace std; int k = 0; vector<int> lotto; void BackTracking(vector<int> answer, int pos) { if (answer.size() == 6) { for (int lotto_number : answer) { printf("%d ", lotto_number); } printf("\n"); return; } for (int i = pos; i < k; i++) { answer.push_back(lotto[i]); BackTracking(answer, i + 1); answer.pop_back(); } } int main(void) { int number = 0; while (1) { scanf("%d", &k); if (k == 0) break; for (int i = 0; i < k; i++) { scanf("%d", &number); lotto.push_back(number); } vector<int> v; BackTracking(v, 0); printf("\n"); if (!lotto.empty()) lotto.clear(); } return 0; } | cs |
728x90
반응형