Conversation
LeetCode: https://leetcode.com/problems/paint-fence/description/ LintCode: https://www.lintcode.com/problem/514/description Description: You are painting a fence of n posts with k different colors. You must paint the posts following these rules: Every post must be painted exactly one color. There cannot be three or more consecutive posts with the same color. Given the two integers n and k, return the number of ways you can paint the fence. Example 1: Input: n = 3, k = 2 Output: 6 Explanation: All the possibilities are shown. Note that painting all the posts red or all the posts green is invalid because there cannot be three posts in a row with the same color. Example 2: Input: n = 1, k = 1 Output: 1 Example 3: Input: n = 7, k = 2 Output: 42 Constraints: 1 <= n <= 50 1 <= k <= 105 The testcases are generated such that the answer is in the range [0, 231 - 1] for the given n and k.
oda
reviewed
Oct 24, 2024
競技プロ就活部PR用/276. Paint Fence.md
Outdated
Owner
Author
There was a problem hiding this comment.
odaさん
ありがとうございます。そうですね、15分以内ではできませんでしたが、解法を見て、n = 4, k = 3の例でやってみて、パターンが見えたので、3回復習時はパターン書いてみるところから書き直しました。
|
綺麗にまとまっていて読みやすかったです(復習になりました) 必須ではないかもですが、行列表現に関しても軽く確認しておくと良いかもしれません。 |
nodchip
reviewed
Oct 28, 2024
競技プロ就活部PR用/276. Paint Fence.md
Outdated
There was a problem hiding this comment.
「1番目、2番目、3番目」という表現が不正確に感じました。現在着目しているポスト、一つ前のポスト、二つ前のポストという意味でしょうか?
Owner
Author
There was a problem hiding this comment.
@nodchip さん
ありがとうございます。
こちらわかりづらくてすみません。
n = 4、k = 3くらいに設定して、n =1, 2, 3の場合を試しに手で書き出してみる。という意図でした。
競技プロ就活部PR用/276. Paint Fence.md
Outdated
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.
LeetCode: https://leetcode.com/problems/paint-fence/description/
LintCode: https://www.lintcode.com/problem/514/description