Skip to content

Create 0_63. Unique Paths II.md#37

Open
irohafternoon wants to merge 1 commit intomainfrom
63.-Unique-Paths-II
Open

Create 0_63. Unique Paths II.md#37
irohafternoon wants to merge 1 commit intomainfrom
63.-Unique-Paths-II

Conversation

@irohafternoon
Copy link
Copy Markdown
Owner

This Problem
Unique Paths II
Next Problem
House Robber

private:
static constexpr int kObstacle = 1;
};
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

読みやすかったです。

個人的には、ある行が全て障害物の場合の打ち切りにあまりメリットを感じず、打ち切りなしのコードの方が気が散らずに読めていいかなと思いました。

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.

ありがとうございます。コードが見にくくなることに加え、ステップ数の削減においてもあまりメリットが期待できなさそうで、現在はない方が良いなと感じています

Comment on lines +143 to +145
if (obstacleGrid[0][0] == kObstacle) {
return 0;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

この判定いりますね。

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.

ありがとうございます。
以下のコードで初めのマスが有効であることを前提にDPをするので、この判定がないとスタート地点が障害物がある場合に誤った結果を返してしまう認識です

Comment on lines +210 to +212
if (*std::max_element(coordinte_to_paths[row].begin(),coordinte_to_paths[row].end()) == 0) {
return 0;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

あってもいいですが、なくてもいいでしょう。

まずは、これによってどれくらいの確率でどれくらい速くなって、どれくらいの確率でどれくらい遅くなるかのバランスですが、ループを2度回すことになるので結構遅くなる感覚があります。

そして、コードが複雑になるデメリットもありますね。

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.

ありがとうございます。
おっしゃる通り、各ループでのステップが倍になるので、枝刈りがない場合はステップ数が2倍になるので、グリッドの上半分までに行き止まりにならない限りは、ステップ数は減らないということになるかと思います。
そしてコードの見やすさが減少してしまうので、「ルートがない場合は、グリッドのかなり序盤(行番号が小さい時点)まで行き止まりになる」ということが事前に分かっている状況でない限り、デメリットの方が多そうだと思いました

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