Open
Conversation
huyfififi
reviewed
Feb 20, 2026
|
|
||
| if candidate_sum <= target_sum { | ||
| combination.push(candidate); | ||
| Self::make_combinations( |
There was a problem hiding this comment.
私は
for i in range(candidate_start, len(candidates)):
...
combination.append(sorted_candidates[i])
make_combinations(i, sum, combination)
combination.pop()のような形しか検討していなかったのですが、t9a-devさんのこの書き方の方が脳への収まりがよく感じました。各ステップで判断すべきことが、今のcandidateを(もう)一回使うか、先に進むか、の二択で直感的に理解しやすいように思いました。
oda
reviewed
Mar 23, 2026
| https://discord.com/channels/1084280443945353267/1233295449985650688/1242146721094570034 | ||
| - step1で時間計算量の見積もりに躓いてかなり時間使ったが、簡単に理解できるものではないという知識があれば避けられたなと思った。 | ||
| candidates[i]の最小が1の場合は、分割数の極限の振る舞いというものを知っている必要がある。ただし、ソフトウェアエンジニアの常識には含まれていなさそう。 | ||
| 今回の問題では制約によりcandidates[i]の最小が2であるので、分割数の極限の振る舞いは関係ないことに注意が必要。 |
There was a problem hiding this comment.
あ、最小が2の場合も分割数で表せてですね
a[i] を i を1以上の数の和で表す方法、b[i] を i を2以上の数の和で表す方法とすると、
a[i+1] の中身は2つに分けられますね。1を1回以上使っているものと0回使っているものです。
0回使っているやつの群れは b[i+1] いますね。1回以上使っているやつの群れから1を一つずつ供出してもらうと、これは a[i] ですね。
つまり、a[i+1] = b[i+1] + a[i] です。要するに、極限の振る舞いは分割数の極限の微分になります。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題: 39. Combination Sum
次に解く問題: 22. Generate Parentheses
ファイルの構成:
./src/bin/<各ステップ>.rs