# 2.1.2.一串數列中取n個數字, 共有幾種組合

* example code

  ```
            class Solution {
                vector<int> hour = {1, 2, 4, 8};
                vector<int> minute = {1, 2, 4, 8, 16, 32};
            public:
                vector<string> readBinaryWatch(int num) {

                    vector<string> res;
                    //初始值: time = 00:00, start point = 0
                    helper(res, make_pair(0, 0), num, 0);
                    return res;
                }
                //res: 儲存字串
                //time: 累積時間
                //num: 剩餘數量
                //start_point: 數量起始值
                void helper(vector<string>& res, pair<int, int> time, int num, int start_point){
                    //終止條件: 剩餘數量=0
                    if(num == 0){
                        res.push_back(to_string(time.first) + (time.second < 10 ? ":0" : ":") + to_string(time.second));
                        return;
                    }
                    for(int i = start_point; i < hour.size() + minute.size(); i++){
                        if(i < hour.size()){
                            //hour
                            time.first = time.first + hour[i];
                            if(time.first < 12){
                                helper(res, time, num - 1, i + 1);
                            }
                            time.first = time.first - hour[i];
                        }else{
                            //minute
                            time.second = time.second + minute[i - hour.size() ];
                            if(time.second < 60){
                                helper(res, time, num - 1, i + 1);
                            }
                            time.second = time.second - minute[i - hour.size() ];
                        }
                    }
                }
            };
  ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/letcode/2.algorithm/2.1.backtracking/212yi-chuanshu-lie-zhong-qu-n-ge-shu-5b572c-gong-you-ji-zhong-zu-he.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
