1 条题解

  • 0
    @ 2025-9-10 9:00:40

    C++ :

    #include <iostream>
    #include <string>
    using namespace std;
    
    int nseq[20];
    
    string mth_seq(int n, int m) {
      if (n == 0) return "";
      for (int j = 0; j < n; j++)
        if (nseq[n-j-1] * nseq[j] > m)
          return "E" + mth_seq(n-j-1, m/nseq[j]) + "S" + mth_seq(j, m%nseq[j]);
        else
          m -= nseq[n-j-1] * nseq[j];
    }
    
    main() {
      nseq[0] = 1;
      for (int i = 1; i <= 19; i++) {
        for (int j = 0; j < i; j++) nseq[i] += nseq[i-j-1] * nseq[j];
      }
      int N, M;
      while ((cin >> N && N) && (cin >> M && M)) {
        if (M-1 >= nseq[N-1])
          cout << "ERROR" << endl;
        else
          cout << mth_seq(N-1, M-1) << endl;
      }
    }
    
    
    • 1

    信息

    ID
    3642
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者