<commit_before>#include "UniqueBinarySearchTrees.hpp"

#include <vector>
using namespace std;

int UniqueBinarySearchTrees::numTrees(int n)
{
  if (n < 0) {
    return 0;
  }

  vector<int> dp(n + 1, 0);
  dp[0] = 1;

  for (int i = 1; i <= n; i++)
    for (int r = 1; r <= i; r++) {
      dp[i] += dp[r - 1] * dp[i - r];
    }

  return dp[n];
}
<commit_msg>Refine Problem 96. Unique Binary Search Trees<commit_after>#include "UniqueBinarySearchTrees.hpp"

#include <vector>
using namespace std;

int UniqueBinarySearchTrees::numTrees(int n)
{
  vector<vector<int>> dp(n + 2, vector<int>(n + 1, 0));

  for (int i = 1; i <= n; i++) {
    dp[i][i] = dp[i][i - 1] = dp[i + 1][i] = 1;
  }

  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n + 1 - l; i++) {
      int j = i + l - 1;

      for (int k = i; k <= j; k++) {
        dp[i][j] += dp[i][k - 1] * dp[k + 1][j];
      }
    }
  }

  return dp[1][n];
}

{'fraction_non_alphanumeric': 0.21069868995633187, 'fraction_numerical': 0.027292576419213975, 'mean_word_length': 2.4734848484848486, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '222667', 'n_tokens_mistral': 428, 'n_tokens_neox': 393, 'n_words': 112}