```
class Solution {
public:
int numTrees(int n) {
vector<int> DP(n+1, 0);
DP[0] = 1;
int i, j;
for(i=1; i<=n; i++)
for(j=1; j<=i; j++)
DP[i] = DP[i] + DP[j-1]*DP[i-j];
return DP[n];
}
};
```