#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() template<class T> bool umin(T &a ,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a ,const T &b){return (a<b?a=b,1:0);} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef long double ld; auto rng=bind(uniform_int_distribution<ll>(1,(ll)1e18),mt19937(time(0))); const int inf = (int)1e9 + 1; const int N = 6000 + 3; int dp[N]; pii par[N]; string get(int i, string db) { // cout << i << endl; if (dp[i] == i) { string ans; for (int t = 0; t < i; ++t) ans += db; return ans; } if (par[i].s == -1) { int x = i / par[i].f; return to_string(x) + "[" + get(par[i].f, db) + "]"; } else { return get(par[i].f, db) + get(par[i].s, db); } } string ans; void rec (int n) { if (n == 0) { return ; } ans += "B"; ans += get(n - 1, "C"); ans += get(n - 1, "EA"); // cout << ans.size() << endl; rec(n - 1); } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); for (int i = 1; i < N; ++i) { dp[i] = i; for (int j = 2; j <= 9; ++j) { if ((i % j) == 0) { if (umin(dp[i], dp[i/j] + 3)) { par[i] = {i / j, -1}; } } } for (int t = 1; t <= i; ++t) { // cout << t<< ' '<<i<<endl; // umin(dp[i], dp[t] + dp[i - t]); if (umin(dp[i], dp[i - t] + dp[t])) { par[i] = {t, i - t}; } } } int n; cin >> n; ans += get(n, "F"); rec(n); ans += get(n, "D"); // ofstream cout("tro0.out"); cout << ans; // ans += "B"; /// lets try // cout << *max_element(dp, dp + N); return 0; } /* 6 6 3 5 4 8 3 7 1 2 1 7 2 18 7 9 3 18 5 17 3 8 14 18 4 7 7 17 3 20 1 18 4 11 10 11 */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() template<class T> bool umin(T &a ,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a ,const T &b){return (a<b?a=b,1:0);} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef long double ld; auto rng=bind(uniform_int_distribution<ll>(1,(ll)1e18),mt19937(time(0))); const int inf = (int)1e9 + 1; const int N = 6000 + 3; int dp[N]; pii par[N]; string get(int i, string db) { // cout << i << endl; if (dp[i] == i) { string ans; for (int t = 0; t < i; ++t) ans += db; return ans; } if (par[i].s == -1) { int x = i / par[i].f; return to_string(x) + "[" + get(par[i].f, db) + "]"; } else { return get(par[i].f, db) + get(par[i].s, db); } } string ans; void rec (int n) { if (n == 0) { return ; } ans += "B"; ans += get(n - 1, "C"); ans += get(n - 1, "EA"); // cout << ans.size() << endl; rec(n - 1); } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); for (int i = 1; i < N; ++i) { dp[i] = i; for (int j = 2; j <= 9; ++j) { if ((i % j) == 0) { if (umin(dp[i], dp[i/j] + 3)) { par[i] = {i / j, -1}; } } } for (int t = 1; t <= i; ++t) { // cout << t<< ' '<<i<<endl; // umin(dp[i], dp[t] + dp[i - t]); if (umin(dp[i], dp[i - t] + dp[t])) { par[i] = {t, i - t}; } } } int n; cin >> n; ans += get(n, "F"); rec(n); ans += get(n, "D"); // ofstream cout("tro0.out"); cout << ans; // ans += "B"; /// lets try // cout << *max_element(dp, dp + N); return 0; } /* 6 6 3 5 4 8 3 7 1 2 1 7 2 18 7 9 3 18 5 17 3 8 14 18 4 7 7 17 3 20 1 18 4 11 10 11 */ |