#include #include #include #include using namespace std; #define LL long long vector solve(int n,int d,string s){ vector res(d + 1,0);//解 vector fact(d + 1, 1);//階乗をメモ int depth = 0;//現在の項を何回微分すれば良いか LL nowC = 1;//現在の項の係数部 int nowD = 0;//現在の項のxの指数部 int nowDepth = 0;//現在の項の必要微分回数 /*階乗計算*/ for (int i = 1; i <= d; i++){ fact[i] = fact[i - 1] * i; } s += '+'; for (auto& var : s){ switch (var){ case '+': if (nowD - nowDepth >= 0){ res[nowD - nowDepth] += nowC*(fact[nowD] / fact[nowD-nowDepth]); } nowC = 1; nowD = 0; nowDepth = 0; case '*': break; case 'd': depth++; case '{': break; case '}': depth--; break; case 'x': nowDepth = depth; nowD++; break; default : nowDepth = depth; nowC = (var - '0'); break; } } return res; } int main(){ int n, d; string s; cin >> n >> d >> s; auto res = solve(n, d, s); for (int i = 0; i < d; i++){ cout << res[i] << " "; } cout << res[d] << endl; return 0; }