276. Paint Fence#24
Open
hiro111208 wants to merge 1 commit into
Open
Conversation
Shunii85
reviewed
May 3, 2026
Comment on lines
+22
to
+24
| tmp = num_ways_prev_1 | ||
| num_ways_prev_1 = (k - 1) * (num_ways_prev_1 + num_ways_prev_2) | ||
| num_ways_prev_2 = tmp |
There was a problem hiding this comment.
tmpは意味がなくて読みにくいので、num_ways_hereで、今のポストまでのパターンを計算しておいて、num_ways_prev2に1を代入、1にhereを代入する、と書くとわかりやすいと思いました。
h-masder
reviewed
May 5, 2026
| return k | ||
| if n == 2: | ||
| return k * k | ||
| num_ways_prev_2 = k |
There was a problem hiding this comment.
もう少し、変数の意図が明確になるといいなと思います
num_ways_up_to_two_posts_before などはいかがでしょうか
Owner
Author
There was a problem hiding this comment.
たしかにnum_ways_prev_2ややわかりづらいかもしれません。
num_ways_up_to_two_posts_before の方がより明確だと思います。
h-masder
reviewed
May 5, 2026
| 1. $post_{n}$を$post_{n-1}$と違う色にする | ||
| - 色の選択肢は$k-1$ | ||
| 2. $post_{n}$と$post_{n-1}$を同じにする | ||
| - 色の選択肢は$k-1$ |
There was a problem hiding this comment.
ここは、「$post_{n}$と$post_{n-1}$を同じに塗れる数は、$post_{n-2}$と違う色になっている$post_(n-1)$の数である、ということかと思いましたが,あっていますでしょうか。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます。その理解で合っています。
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.
This problem: 276. Paint Fence
Next problem: 198. House Robber