仅供参考 #第二题 (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

相关推荐

bangbangba...:感觉三个项目可以融在一起,比如上层是用手写的epoll,然后到tcp聊天层,然后你写了一个后台监控(不过我也不懂c++,但是感觉写一个大项目比三个小项目要好)
我的求职进度条
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务