Skip to content

322. Coin Change#38

Open
hemispherium wants to merge 2 commits into
mainfrom
0322-coin-change
Open

322. Coin Change#38
hemispherium wants to merge 2 commits into
mainfrom
0322-coin-change

Conversation

@hemispherium
Copy link
Copy Markdown
Owner

@hemispherium hemispherium self-assigned this May 1, 2026
Comment thread 0322-coin-change/memo.md
@@ -0,0 +1,13 @@
### step1

DFSでコイン1枚ずつ遷移させていく方法しか思いつかず、TLEしてしまったのでChatGPTにDPで解き直してもらった。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TLEしたコードも参考に貼っておくと、良いと思います。

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.

そうですね。今回はもう消してしまってないので次回から参考に貼るようにします。

Copy link
Copy Markdown

@liquo-rice liquo-rice May 8, 2026

Choose a reason for hiding this comment

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

LeetCodeのSubmissionsタブから見れないですかね?

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.

ありがとうございます!見られました!こちらの機能知らなかったです。あとで追加しておきます。

class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
const int INF = 1e9;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1e9という数はどこから来ましたか?

INT_MAXを使わない理由はありますか?

Copy link
Copy Markdown
Owner Author

@hemispherium hemispherium May 7, 2026

Choose a reason for hiding this comment

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

なんとなく大きな数ということでこう書いてしまいました。INT_MAXやstd::numeric_limits<int>::max()を使うようにします。


for (int i = 0; i <= amount; i++) {
for (int coin : coins) {
if (i <= amount - coin) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i + coin <= amountとするのが自然に思いますが、この形にするのは何か意図はありますか?

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.

i + coinがオーバーフローしてしまうことがあるためこう書いた気がします。

Comment thread 0322-coin-change/memo.md
他の方のPRを見ていると、配るDP, もらうDPに関していくつか記述があったので調べてみた。(https://algo-method.com/descriptions/78)
今回書いたDPは配るDPらしい。

### step2
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

他の人のコードを読んでみましたか?これ以外にも、再帰+memoizationの方法とかがあると思います。

Comment thread 0322-coin-change/memo.md

DFSでコイン1枚ずつ遷移させていく方法しか思いつかず、TLEしてしまったのでChatGPTにDPで解き直してもらった。
他の方のPRを見ていると、配るDP, もらうDPに関していくつか記述があったので調べてみた。(https://algo-method.com/descriptions/78)
今回書いたDPは配るDPらしい。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

貰うDPの方でも書けますか?

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.

2 participants