intsolve(int begin, int end) { if (begin >= end) return1; if (DP[begin][end]) return DP[begin][end]; int f = 0; for (int i = begin; i <= end; ++i) { int r = solve(begin,i-1); int l = solve(i+1,end); f += r * l; } DP[begin][end] = f; return f; }
intnumTrees(int n){ if (1 >= n) return1; DP = vector<vector<int>>(n+1,vector<int>(n+1,0)); solve(1,n); int result = 0; return DP[1][n]; } };