1 条题解
-
1
#include <iostream> #include <string> #include <vector> using namespace std; // 返回是否存在下一个Jam数字 bool nextJam(vector<int>& a, int t) { int w = a.size(); int i = w - 1; while (i >= 0) { // 当前位置可以增大,且增大后,后面还有足够的递增空间 int max_possible = t - (w - 1 - i); if (a[i] < max_possible) { a[i]++; for(int j = i + 1; j < w; j++) { a[j] = a[j-1] + 1; } return true; } i--; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int s, t, w; string str; cin >> s >> t >> w; cin >> str; vector<int> a(w); for(int i = 0; i < w; i++) { a[i] = str[i] - 'a' + 1; } int cnt = 0; while(cnt < 5) { if(!nextJam(a, t)) break; for(int num : a) { cout << (char)(num - 1 + 'a'); } cout << '\n'; cnt++; } return 0; }
- 1
信息
- ID
- 686
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 6
- 已通过
- 5
- 上传者