仅供参考 #第二题 (1369)#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; }
点赞 2

相关推荐

认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 11:15
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务