解题思路:
用官方数据跑应该是妥妥的超时的,可能是因为数据比较水吧,居然过了...
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <string> #include <queue> #include <algorithm> #include <stdio.h> #define N 27 using namespace std; vector<string> strSet; void DFS(char curAlpha,const char maxAlpha, string curStr, vector<string>& strSet, const int len, const string& startStr) { static int count; static bool gotStartStr = false; if (count >= 5) return; else if (curStr.length() == len) { strSet.push_back(curStr); if (curStr == startStr) gotStartStr = true; else if (gotStartStr) count += 1; return; } else if (curAlpha > maxAlpha) return; else { string bakStr = curStr; curStr += curAlpha; DFS(curAlpha + 1, maxAlpha, curStr, strSet, len, startStr); curStr = bakStr; DFS(curAlpha + 1, maxAlpha, curStr, strSet, len, startStr); } } int main(int argc, char** argv) { int s = 0, t = 0, len = 0; string startStr; cin >> s >> t >> len; cin >> startStr; string str; DFS('a' + s - 1, 'a' + t - 1, str, strSet, len, startStr); for (vector<string>::iterator it = strSet.end() - 5; it < strSet.end(); it++) cout << *it << endl; return 0; }
0.0分
0 人评分
字符串问题 (C语言代码)浏览:1504 |
C语言训练-排序问题<1> (C语言代码)浏览:599 |
1118(求助_已解决)浏览:329 |
Tom数 (C语言代码)浏览:492 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:661 |
链表数据求和操作 (C语言代码)浏览:941 |
1005答案错误为什么浏览:1975 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:612 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:482 |
循环链表与单个结点删除浏览:1102 |