仅供参考 #第二题 #include<iostream> #include<vector> using namespace std; void DFS(int nowDepth, int maxDepth, int n, int k, vector<string> &ans, string tmpSeq){     if(nowDepth >= maxDepth){         ans.push_back(tmpSeq);         return;     }     if(n > 0){         // choose "*"         tmpSeq += "*";         DFS(nowDepth+1, maxDepth, n-1, k, ans, tmpSeq);         tmpSeq.pop_back();     }     if(k > 0){         // choose "|"         tmpSeq += "|";         DFS(nowDepth+1, maxDepth, n, k-1, ans, tmpSeq);         tmpSeq.pop_back();     } } int main(){     int n, k;     cin >> n >> k;     vector<string> ans;     string tmpSeq = "";     DFS(0, n+k-1, n, k-1, ans, tmpSeq);     cout << ans.size() << endl;     for(auto str: ans){         cout << str << endl;     }     system("pause");     return 0; }