[itint5]棋盘漫步
要注意dp[0][0]要初始化为1。
int totalPath(vector<vector<bool> > &blocked) { int m = blocked.size(); if (m == 0) return 0; int n = blocked[0].size(); if (n == 0) return 0; vector<vector<int> > dp(m); for (int i = 0; i < m; i++) { dp[i].resize(n, 0); } if (!blocked[0][0]) dp[0][0] = 1; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (blocked[i][j]) { dp[i][j] == 0; } else { if (i-1 >= 0) dp[i][j] += dp[i-1][j]; if (j-1 >= 0) dp[i][j] += dp[i][j-1]; } } } return dp[m-1][n-1]; }