걍 조합문제
nCr = n-1Cr-1 + n-1Cr 큰 문제는 작은 문제들의 해결을 통해 해결할 수 있다. 를 순환함수로 작성하여 풀이하면 쉽게 풀 수 있음
void select(int nextIndex, vector<int> arr) { // basecase // 정답이 나오면 출력 if(arr.size() == 6) { for(int i = 0; i<6; i++) { cout<<arr[i]<<' '; } cout<<endl; return; } else if (nextIndex >= n) { return; } arr.push_back(candidates[nextIndex]); select(nextIndex + 1, arr); arr.pop_back(); select(nextIndex + 1, arr); }
Last updated 6 years ago
Was this helpful?