Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 05d98fd

Browse files
Create 3665.Twisted-Mirror-Path-Count.cpp
1 parent 7c47250 commit 05d98fd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
int dp[501][501][2];
3+
public:
4+
int uniquePaths(vector<vector<int>>& grid) {
5+
int M = 1e9+7;
6+
int m = grid.size(), n = grid[0].size();
7+
for (int i=0; i<m; i++)
8+
for (int j=0; j<n; j++) {
9+
if (i==0 && j==0) {
10+
dp[i][j][0] = 1;
11+
continue;
12+
}
13+
int ret = 0;
14+
if (i>=1 && j>=0) {
15+
if (grid[i-1][j]==0)
16+
dp[i][j][0] += dp[i-1][j][0]+dp[i-1][j][1];
17+
else
18+
dp[i][j][0] += dp[i-1][j][1];
19+
}
20+
if (i>=0 && j-1>=0) {
21+
if (grid[i][j-1]==0)
22+
dp[i][j][1] += dp[i][j-1][0]+dp[i][j-1][1];
23+
else
24+
dp[i][j][1] += dp[i][j-1][0];
25+
}
26+
dp[i][j][0]%=M;
27+
dp[i][j][1]%=M;
28+
}
29+
return (dp[m-1][n-1][0]+dp[m-1][n-1][1])%M;
30+
}
31+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /