0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競プロ日記#25/03/03

Posted at

アルゴ式-回文を作る

  • 再帰関数でサンドすることを考える
  • その時に再帰を切り上げる条件としてif(N == 0)にする
  • 真ん中は常にN - 1
string func(string S,int N){
    int i = 0;
    if (N == 0){
        return "";
    }
    int indexCenter = N - 1;
    return func(S,N - 1) +  S.at(indexCenter) + func(S,N - 1);
}

アルゴ式-部下の人数

  • 再帰関数の定義が難しかった。(要復習)。
    おそらく(直属の部下 + その人自身)というのを再帰関数で表現している。そのためにXの直属の部下の人数分だけ範囲for文で回している
int num_of_staffs(int X, vector<vector<int>> &staffs) {
    int result = 0;
    for (int staff: staffs[X]) {
        // (社員 staff の部下の人数) + 1(社員 staff) 
        result += num_of_staffs(staff, staffs) + 1;
    }
    return result;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?