-
Notifications
You must be signed in to change notification settings - Fork 0
62. Unique Paths #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #if __has_include("../debug.hpp") | ||
| #include "../debug.hpp" | ||
| #endif | ||
| // ここまでローカルでのデバッグ用なので気にしないでください -------------------- | ||
|
|
||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| // <時間> | ||
| // 10分 | ||
| // <感想> | ||
| // 最初計算量の見積もりをミスしていて再帰で書いていた。 | ||
| // 途中で間違いに気づき、メモ化再帰→2次元DPみたいな思考の流れ。 | ||
| // しばらく競プロ等をしていなかったのでDPを書くのに手こずった。 | ||
| // なまるのが早いなと思う。(10分で書けたのが驚き) | ||
| // <コメント> | ||
| // - DPを競プロでしか書いたことがなく、 | ||
| // エンジニアにとってなじみのあるパターンが何か分からないので | ||
| // 他の人のレビューを見てみる | ||
| // - 見てみたが大して差があるように感じないのでこのまま完成とする | ||
| // - 一応いくつか気になる点があるが、 | ||
| // この例では質問するのに適切でないと感じるのでとりあえず次に進む | ||
| class Solution { | ||
| public: | ||
| int uniquePaths(int m, int n) { | ||
| vector<vector<int>> num_paths(m, vector<int>(n)); | ||
| for (int i = 0; i < m; ++i) num_paths[i][0] = 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 私はぶら下がりは避けますね。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 僕はこちらで行かせていただきます(チームの時はチームに従います)
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ちなみに↑のHistorical reasonsってどういう意味か聞いてもよいですか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 書いた人に聞かないと分かりません。どっかのメーリングリストでやりとりがおこなわれておりました。 ただ、昔、慣習的に使われていた、(から好ましくないが慣れて読める人も多いので許す)くらいの温度感でしょう。 現代的な言語、たとえば Rust や Go や Swift などは {} が必要です。いらないのは C C++ Java などですね。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほどです。ありがとうございます! |
||
| for (int i = 0; i < n; ++i) num_paths[0][i] = 1; | ||
| for (int i = 1; i < m; ++i) { | ||
| for (int j = 1; j < n; ++j) { | ||
| num_paths[i][j] = num_paths[i - 1][j] + num_paths[i][j - 1]; | ||
| } | ||
| } | ||
| return num_paths[m - 1][n - 1]; | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10分で書けているなら、この問題はいいでしょう。
CPython の comb のコードを読んでいる人もいました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
この方などですね
nittoco/leetcode#26