문제 : http://jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=458&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 | #include <iostream> #include <vector> void Throw(std::vector<int>& parDiceList, const int parThrowNum , const int parTargetNum,const int parOrder) { if (parOrder == parThrowNum) { int nSumOfList = 0; for (auto order : parDiceList) { nSumOfList += order; } if (nSumOfList == parTargetNum) { for (auto order : parDiceList) { std::cout << order << " "; } std::cout << std::endl; } return; } for (int i = 0; i < 6; ++i) { parDiceList.push_back(i + 1); Throw(parDiceList, parThrowNum, parTargetNum, parOrder + 1); parDiceList.pop_back(); } } int main() { int nNumOfThrow; int nTargetNum; std::vector<int> diceList; diceList.clear(); std::cin >> nNumOfThrow; std::cin >> nTargetNum; getchar(); Throw(diceList,nNumOfThrow, nTargetNum, 0); return 0; } | cs |
'알고리즘 문제' 카테고리의 다른 글
ID : 팩토리얼 난이도 : 하 (0) | 2017.11.30 |
---|---|
ID : 주사위 던지기1 난이도 : 하 (재귀 완전탐색) (0) | 2017.11.27 |
ID : CLOCKSYNC 난이도 : 중 (재귀 완전탐색) (0) | 2017.11.21 |
ID : TSP1(여행하는 외판원1) 난이도 : 하 (재귀 완전탐색) (0) | 2017.11.17 |
ID : BOARDCOVER 난이도 : 하 (재귀 완전탐색) (0) | 2017.11.15 |