Now I believe thoughts leading to DP is brutal DFS.. DFS is brutal force enumeration, but that's too much and naive. We need pruning. So, DFS + Pruning leads to DP! Equation is simple in this case. 1A!
class Solution { public: #define MAXN 101 int uniquePaths(int m, int n) { // Initial thought was DFS, which is brutal force. // So try pruning.. DFS + Pruning means DP int A[MAXN][MAXN]; for (int i = 0; i <= m; i++) A[i][0] = 0; for (int i = 0; i <= n; i++) A[0][i] = 0; A[1][1] = 1; for (int i = 1; i <= m; i ++) for (int j = 1; j <= n; j ++) { if (i == 1 && j == 1) continue; A[i][j] = A[i - 1][j] + A[i][j - 1]; } return A[m][n]; } };