문제 : http://jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=449&sca=2070
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #include <iostream> #include <vector> #include <algorithm> class Dice { public: int mnNumOfThrow; int mnType; std::vector<int> mNumList; void Show(); private: void _Type1(int); void _Type2(int, int); void _Type3(int); }; int main() { Dice dice; std::cin >> dice.mnNumOfThrow; getchar(); std::cin >> dice.mnType; getchar(); dice.Show(); return 0; } void Dice::Show() { mNumList.clear(); switch (mnType) { case 1: _Type1(1); break; case 2: _Type2(1, 0); break; case 3: _Type3(1); break; } } void Dice::_Type1(int parOrder) { //기저사례 if (parOrder > mnNumOfThrow) { for (int tmp : mNumList) std::cout << tmp << " "; std::cout << std::endl; return; } for (int i = 0; i < 6; ++i) { mNumList.push_back(i + 1); _Type1(parOrder + 1); mNumList.pop_back(); } } void Dice::_Type2(int parOrder, int parExept) { //기저사례 if (parOrder > mnNumOfThrow) { for (int tmp : mNumList) std::cout << tmp << " "; std::cout << std::endl; return; } for (int i = parExept; i < 6; ++i) { mNumList.push_back(i + 1); _Type2(parOrder + 1, i); mNumList.pop_back(); } } void Dice::_Type3(int parOrder) { //기저사례 if (parOrder > mnNumOfThrow) { for (int tmp : mNumList) std::cout << tmp << " "; std::cout << std::endl; return; } for (int i = 0; i < 6; ++i) { std::vector<int>::iterator tmpIter; tmpIter = find(mNumList.begin(), mNumList.end(), i+1); if (tmpIter != mNumList.end()) { } else { mNumList.push_back(i + 1); _Type3(parOrder + 1); mNumList.pop_back(); } } } | cs |
'알고리즘 문제' 카테고리의 다른 글
ID : 주사위던지기2 난이도 : 하 (재귀) (0) | 2017.12.01 |
---|---|
ID : 팩토리얼 난이도 : 하 (0) | 2017.11.30 |
ID : CLOCKSYNC 난이도 : 중 (재귀 완전탐색) (0) | 2017.11.21 |
ID : TSP1(여행하는 외판원1) 난이도 : 하 (재귀 완전탐색) (0) | 2017.11.17 |
ID : BOARDCOVER 난이도 : 하 (재귀 완전탐색) (0) | 2017.11.15 |