Skip to content

276. Paint Fence#24

Open
hiro111208 wants to merge 1 commit into
mainfrom
276-paint-fence
Open

276. Paint Fence#24
hiro111208 wants to merge 1 commit into
mainfrom
276-paint-fence

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

This problem: 276. Paint Fence

Next problem: 198. House Robber

Comment thread 276_paint_fence/step3.md
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tmpは意味がなくて読みにくいので、num_ways_hereで、今のポストまでのパターンを計算しておいて、num_ways_prev2に1を代入、1にhereを代入する、と書くとわかりやすいと思いました。

Comment thread 276_paint_fence/step2.md
return k
if n == 2:
return k * k
num_ways_prev_2 = k
Copy link
Copy Markdown

@h-masder h-masder May 5, 2026

Choose a reason for hiding this comment

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

もう少し、変数の意図が明確になるといいなと思います
num_ways_up_to_two_posts_before などはいかがでしょうか

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

たしかにnum_ways_prev_2ややわかりづらいかもしれません。
num_ways_up_to_two_posts_before の方がより明確だと思います。

Comment thread 276_paint_fence/step1.md
1. $post_{n}$を$post_{n-1}$と違う色にする
- 色の選択肢は$k-1$
2. $post_{n}$と$post_{n-1}$を同じにする
- 色の選択肢は$k-1$
Copy link
Copy Markdown

@h-masder h-masder May 5, 2026

Choose a reason for hiding this comment

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

ここは、「$post_{n}$と$post_{n-1}$を同じに塗れる数は、$post_{n-2}$と違う色になっている$post_(n-1)$の数である、ということかと思いましたが,あっていますでしょうか。

Copy link
Copy Markdown
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