322. Coin Change#38
Open
hemispherium wants to merge 2 commits into
Open
Conversation
liquo-rice
reviewed
May 1, 2026
| @@ -0,0 +1,13 @@ | |||
| ### step1 | |||
|
|
|||
| DFSでコイン1枚ずつ遷移させていく方法しか思いつかず、TLEしてしまったのでChatGPTにDPで解き直してもらった。 | |||
Owner
Author
There was a problem hiding this comment.
そうですね。今回はもう消してしまってないので次回から参考に貼るようにします。
Owner
Author
There was a problem hiding this comment.
ありがとうございます!見られました!こちらの機能知らなかったです。あとで追加しておきます。
| class Solution { | ||
| public: | ||
| int coinChange(vector<int>& coins, int amount) { | ||
| const int INF = 1e9; |
There was a problem hiding this comment.
1e9という数はどこから来ましたか?
INT_MAXを使わない理由はありますか?
Owner
Author
There was a problem hiding this comment.
なんとなく大きな数ということでこう書いてしまいました。INT_MAXやstd::numeric_limits<int>::max()を使うようにします。
|
|
||
| for (int i = 0; i <= amount; i++) { | ||
| for (int coin : coins) { | ||
| if (i <= amount - coin) { |
There was a problem hiding this comment.
i + coin <= amountとするのが自然に思いますが、この形にするのは何か意図はありますか?
Owner
Author
There was a problem hiding this comment.
i + coinがオーバーフローしてしまうことがあるためこう書いた気がします。
| 他の方のPRを見ていると、配るDP, もらうDPに関していくつか記述があったので調べてみた。(https://algo-method.com/descriptions/78) | ||
| 今回書いたDPは配るDPらしい。 | ||
|
|
||
| ### step2 |
There was a problem hiding this comment.
他の人のコードを読んでみましたか?これ以外にも、再帰+memoizationの方法とかがあると思います。
|
|
||
| DFSでコイン1枚ずつ遷移させていく方法しか思いつかず、TLEしてしまったのでChatGPTにDPで解き直してもらった。 | ||
| 他の方のPRを見ていると、配るDP, もらうDPに関していくつか記述があったので調べてみた。(https://algo-method.com/descriptions/78) | ||
| 今回書いたDPは配るDPらしい。 |
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.
この問題:https://leetcode.com/problems/coin-change/description/
次に解く問題:https://leetcode.com/problems/search-insert-position/description/