Skip to content

Conversation

@Ryotaro25
Copy link
Owner

問題へのリンク
https://leetcode.com/problems/permutations/description/

問題文(プレミアムの場合)

備考

次に解く問題の予告
Subsets

フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step2_2.cpp、step2_3.cpp、step2_4.cpp、step3.cppとmemo.mdとなります。

memo.md内に各ステップで感じたことを追記します。

次にその数字をもう一度選ぼうとすると同じ順列が再度生成される

# step1が終わって疑問に思ったこと
・問題の制約上サイズ6が上限だがこれが、10であっらい100とかならどの様に解くのか?
Copy link

Choose a reason for hiding this comment

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

100! はもう158桁とかなので現実的には無理ですね。

return;
}

for (int num : nums) {
Copy link

Choose a reason for hiding this comment

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

ここで nums で回すと計算量が少し悪くなりますが、そもそも重いので状況次第ですね。

Copy link
Owner Author

Choose a reason for hiding this comment

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

@oda
レビューありがとうございます。
step2_3で重複のチェク確認用にvector usedを用いました。まだこちらの方がマシでしょうか。
ただ実装は大変だと感じました。

Copy link

Choose a reason for hiding this comment

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

set で notused を持てばいいです。

Copy link
Owner Author

Choose a reason for hiding this comment

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

@oda
ありがとうございます。step4にsetを用いた実装を追加しました。使用済みか使用済みでないかの管理をvector から分離した方がしっくりきました。
5dd3192

Copy link

Choose a reason for hiding this comment

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

あ、ここ nums で回しちゃうと、O(n! * n) の n が残っちゃうんですね。

ただ、変更しながらループで回すことはできないので、コピーすることになります。
それでも、最後の n はなくなります。

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