Skip to content

Conversation

@Ryotaro25
Copy link
Owner

@Ryotaro25 Ryotaro25 commented Mar 16, 2025

問題へのリンク
https://leetcode.com/problems/generate-parentheses/description/

問題文(プレミアムの場合)

備考

次に解く問題の予告

フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cpp、memo.cppとmemo.mdとなります。

memo.md内に各ステップで感じたことを追記します。

closeはopen以下でないと追加できない
closeの数 > openの数にはならない

memo.cppを実装(nittocoさんの回答を参照)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変わり種だと、

開き+閉じ*(0~ここまでの開きの数までのどれか)までを一つの仕事とみるという仕事の分担方法もあるように思います。
という方法も考えました。
https://discord.com/channels/1084280443945353267/1218823830743547914/1231546400714788864

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oda
レビューありがとうございます。
解法を追加してみました。

開き+閉じ*(0~ここまでの開きの数までのどれか)までを一つの仕事とみるという仕事の分担方法
fc8eba9

STLに基づいた選択肢(mapなら...set...ならこうするだろうのような)は少しは見えるようになってきたのですが、まだまだこのあたりの選択肢は見えていないですね。。。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いやー、まあ、これは見えなくてもいいんじゃないでしょうか。

https://github.com/nittoco/leetcode/pull/43/commits/e373af0cefa8ca2b5b73a4fb901666bd0880c8bd


・カタラン数という言葉を初めて聞いた
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カタラン数は、「高校生でも分かるがあんまり大事ではないので高校範囲に入っていないがたまに大学受験で背景を知らなくても不利にならない程度に出題される」というものです。

知らなくてもいいです。

https://github.com/frinfo702/software-engineering-association/pull/10

>時間計算量: O(n * 2^(2n)) (文字列の任意の位置で開き括弧/閉じ括弧が許される仮定の甘い見積もり。厳密には n x カタラン数でO(4^n/(sqrt(n)))? (ref: https://en.wikipedia.org/wiki/Catalan_number))
カタラン数:C_n = (2n)!/(n + 1)!n! これが4^n / n^(3/2)sqrt(pi)でオーダーを用いるので省略されて最終的にO(4^n / sqrt(n))になるのか
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カタラン数のスターリングの公式による近似で、この公式は物理学だと統計力学でとても使います。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。
他の方のメモでも出てくる名前だったので、こういうものもあるぐらいで覚えておきます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants